Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a UIView that has an image and some buttons as its subviews. I'd like to get a "snapshot" image of it using renderInContext, or other method.

[clefView.layer renderInContext:mainViewContentContext];

If I pass it my UIView (as above) then I get a blank bitmap. None of the children are rendered into the bitmap.

If I pass it the child view that is the image, then I get an image of that bitmap, and, unsurprisingly, none of its siblings (buttons).

I was sort of hoping that renderInContext would take the image and all it's visible children and render it into a bitmap. Has anyone have any ideas how to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
313 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try something like this:

UIGraphicsBeginImageContext(clefView.bounds.size);
[clefView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...