Can I somehow programmatically make a print screen of one ImageView?
Let's say I'm displaying big photos, with different sizes, scaled automatically (AspectFit) to screen size, centered and with black background. I would like to capture the scaled image including the black imageview background to have 320x480 image to work with.
So how to change for example 350x600 image to 320x480 with black border and without any other elements (buttons, labels) overlaying this imageview? On Android I'm just capturing screen buffer but for iPhone I really have no idea how to do it...
Thanks in advance!
UIGraphicsBeginImageContext(<specify your size here as CGRect>);
[<yourImageView or view you want to convert in image>.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
The viewImage
is output. As you want a black border so you can have a logic like this, add you imageView
on a UIView with blackBackroundColor
as black(remember this view's frame should be greater than your imageView's frame with some margin from each side so that you can have your border)..... and now in [<yourView>.layer renderInContext:UIGraphicsGetCurrentContext()];
use this method.