11

I have imageA (taken from the users iPhone camera) and imageB, an image with a silly boarder (for eg) with plenty of transparent alpha space.

What I would like to to do is to merge these two images, laying imageB over imageA, and then saving them as imageC for other work.

Is there a way to do this?

Cheers

I've got this so far

-(void)merge
{
    CGSize size = CGSizeMake(320, 480);
    UIGraphicsBeginImageContext(size);

    CGPoint thumbPoint = CGPointMake(0,0);
    UIImage *imageA = imageView.image;
    [imageA drawAtPoint:thumbPoint];

    UIImage* starred = [UIImage imageNamed:@"imageB.png"];

    CGPoint starredPoint = CGPointMake(0, 0);
    [starred drawAtPoint:starredPoint];

    UIImage *imageC = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    imageView.image = imageC;
}

I can't see/dont know what I'm doing wrong here

WrightsCS
  • 50,205
  • 22
  • 134
  • 184
Sam Jarman
  • 7,187
  • 14
  • 51
  • 99

2 Answers2

3

Note that for retina support you should use: UIGraphicsBeginImageContextWithOptions(size, YES, 0); // 0 means let iOS deal with scale for you

Geva
  • 820
  • 6
  • 14
3

That code looks correct (though I would recommend converting it to use a created CGBitmapContext for thread-safety), but is imageB supposed to be a JPEG? JPEGs don't support transparency, so, in order for the blending to work, it should really be a PNG.

Justin Spahr-Summers
  • 16,819
  • 2
  • 60
  • 78