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

4

3 回答 3

4

希望以下方法对您有所帮助。

-(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;
}
于 2013-03-20T07:38:56.377 回答
3

我拍摄了一个设置在主图像上的徽标图像作为应用程序参考。

所以你可以参考这个,试试你的图片。

根据您的图像设置宽度(w)和高度(h)。

尝试这个 ::

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;

希望,这会帮助你。

谢谢。

于 2013-03-20T07:19:15.853 回答
0

为什么你不只为那部分截屏??

于 2013-03-20T09:27:10.330 回答