开发者

Saving two Overlapping UIImage

开发者 https://www.devze.com 2023-03-12 13:15 出处:网络
I am trying to build a photo frame application on iphone. I made the frame it is transparent in png formate, then by choosing photos and was placed behind the frame layer in the interface builder.

I am trying to build a photo frame application on iphone. I made the frame it is transparent in png formate, then by choosing photos and was placed behind the frame layer in the interface builder.

In interface builder they are placed well and fit well. Now my problem is how can i save them into one picture.

Here is the code i have, but the saving part keep crashing.

-(IBAction) saveImage:(id)sender{

    imagefront .backgroundCo开发者_如何转开发lor = [UIColor clearColor]; //This sets your backgroung to transparent. 
    imagefront.opaque = NO;
    [imageView bringSubviewToFront:imagefront];

    UIImage *overlappedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();


    UIImageWriteToSavedPhotosAlbum(overlappedImage, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);
}

Imagefront is the photoframe while imageView is the photo.

Thank you.


Your current approach is incorrect. You will need to do this to get the image.

UIGraphicsBeginImageContext(imageView.frame.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsGetCurrentContext();

This is assuming that imageView has imageFront as its subview as suggested by the code you've posted.

0

精彩评论

暂无评论...
验证码 换一张
取 消