1

In my application I have two UIImageViews which is overlayed one over the other. i.e ) UIImageView-2 is placed on UIImageView-1. The image in UIImageView-2 is transparent, so now I have image over another image. Now I need to save these two as a single image. Is it possible in ios? Please advice..

The sample view is as below: The red mark is an image in a view over tennis ball image view.

enter image description here

laxonline
  • 2,657
  • 1
  • 20
  • 37
2vision2
  • 4,933
  • 16
  • 83
  • 164
  • Here is the answer which you looking for this exactly slimier to your need. visit: http://stackoverflow.com/questions/12453913/how-can-i-add-two-uiimageview-and-save-it-to-iphone-photo-gallery-in-iphone-appl –  Mar 20 '13 at 07:14

3 Answers3

4

Hope following method will help you.

-(CGImageRef )mergedImageFromImageOne:(UIImage *)imageOne andImageTwo:(UIImage *)imageTwo
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    CGSize imageSize = imageOne.size;

    UIGraphicsBeginImageContext(sizeVideo);

    [imageOne drawInRect:CGRectMake(0,0,imageSize.width,imageSize.height)];

    [imageTwo drawInRect:CGRectMake(0,0,imageSize.width,imageSize.height) alpha:1];

    CGImageRef imageRefNew =  CGImageCreateWithImageInRect(UIGraphicsGetImageFromCurrentImageContext().CGImage, CGRectMake(0,0,imageOne.width,imageOne.height));

    UIGraphicsEndImageContext();

    [pool release];

    return imageRefNew;
}
Kunal
  • 649
  • 4
  • 13
3

I've taken one Logo Image which is set on main image as application ref.

So you can refer this, try with your images.

set width(w) & height(h) as per your image.

Try this ::

UIImage *img_Logo = [UIImage imageNamed:@"Img_Logo.png"];

CGSize newSize = CGSizeMake(w, h);
UIGraphicsBeginImageContext(newSize);

// Use existing opacity as is
[main_image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

// Apply supplied opacity
[img_Logo drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:0.8];

main_image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

imgView.image = main_image;

Hope, this'll help you.

Thanks.

Manann Sseth
  • 2,745
  • 2
  • 30
  • 50
0

Why you are not taking screenshot for only that portion??

user1673099
  • 3,293
  • 7
  • 26
  • 57