0

i have made a camera app in which i click an image and cut it in half, then i click an other image and cut other half from it.
Then these two images are merged i have accomplished this task successfully but the problem is the merging is not smooth.

There is a clear separation between two halves....I want to know how to smooth it up?

//------merging the two images------
- (UIImage*)mergeImage:(UIImage*)first withImage:(UIImage*)second
{
    // get size of the first image
    CGImageRef firstImageRef = first.CGImage;
    CGFloat firstWidth = CGImageGetWidth(firstImageRef);
    CGFloat firstHeight = CGImageGetHeight(firstImageRef);
    
    // get size of the second image
    CGImageRef secondImageRef = second.CGImage;
    CGFloat secondWidth = CGImageGetWidth(secondImageRef);
    CGFloat secondHeight = CGImageGetHeight(secondImageRef);
    
    // build merged size
    CGSize mergedSize = CGSizeMake((firstWidth+secondWidth), MAX(firstHeight, secondHeight));
    
    // capture image context ref
    UIGraphicsBeginImageContext(mergedSize);
    
    //Draw images onto the context
    [first drawInRect:CGRectMake(0, 0, firstWidth, firstHeight)];
    //[second drawInRect:CGRectMake(firstWidth, 0, secondWidth, secondHeight)];
    [second drawInRect:CGRectMake(firstWidth, 0, secondWidth, secondHeight) blendMode:kCGBlendModeNormal alpha:1.0];
    
    // assign context to new UIImage
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // end context
    UIGraphicsEndImageContext();
    
    return newImage;
   
}

Thanks

(i accept downvote as healthy criticism but pls gv rsn so that i can improve)

amar
  • 4,285
  • 8
  • 40
  • 52
  • would it be possible to REALLY merge the binary data of these two images, so you only have to draw one image? – Fab1n Aug 30 '12 at 09:40
  • Do both images always have the same aspect ration/dimensions? can the user adjust this like an aspect fill/fit? – Pochi Aug 30 '12 at 09:51
  • @luis Oscar yeah that assumption can be made – amar Aug 31 '12 at 09:22

2 Answers2

4

if i m not wrong then you want this.

UIImageView *imgView1, *imgView2, *imgView3;
imgView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image1"]];
imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image2"]];
imgView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image3"]];
imgView1.frame = CGRectMake(0, 0, 50, 50);
imgView2.frame = CGRectMake(50, 50, 100, 100);
imgView3.frame = CGRectMake(100, 100, 200, 200);
[referenceView addSubview:imgView1];
[referenceView addSubview:imgView2];
[referenceView addSubview:imgView3];
UIGraphicsBeginImageContext(referenceView.bounds.size);
[referenceView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
resultView = [[UIImageView alloc] initWithImage:finalImage];
resultView.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:resultView];
referenceView.hidden = YES;
Hiren gardhariya
  • 1,247
  • 10
  • 29
0
UIImageView *referenceView = [[UIImageView alloc]init];
referenceView.frame = CGRectMake(0, 0, 1024, 768);
referenceView.hidden = NO;

[self.view insertSubview:referenceView belowSubview:selfView];

UIImageView *imgView1, *imgView2,*imgView3;
imgView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image1"]];
imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image2"]];
imgView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image3"]];


imgView1.frame = CGRectMake(0, 0, 50, 50);
imgView2.frame = CGRectMake(50, 50, 100, 100);
imgView3.frame = CGRectMake(100, 100, 200, 200);

[referenceView addSubview:imgView1];
[referenceView addSubview:imgView2];
[referenceView addSubview:imgView3];
UIImage *finalImage = nil;
UIGraphicsBeginImageContext(referenceView.bounds.size);
[referenceView.layer renderInContext:UIGraphicsGetCurrentContext()];
finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return finalImage;
gaurav
  • 357
  • 1
  • 4
  • 13