1

I have uiview and i want to convert that view to image which is working quite well but when i pressed the home button of iphone and run the app again the image become zoom in .Here is my code to converting view to image.

When the app 1st time run

After pressing the home button and run the app again.

- (UIImage *)captureView {
        CGRect rect = [myview bounds];
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        [myview.layer renderInContext:context];
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return img;

 }
 checkImage.image = [self captureView];
iOS developer
  • 68
  • 2
  • 12

3 Answers3

1

here this code is not wrong but you used some other object instead of whole view . i don't know but try to use that view bounds in which that whole Image display.. See my answer same like your this answer from this bellow link..

how to capture uiview top uiview

Also try with self.view instead of myView in your code.

add this code instead of your checkImage.image = [self captureView]; line..

 UIImageView *imgTempHeader = [[UIImageView alloc]initWithImage:[self captureView]];
 imgTempHeader.frame = self.view.frame;
 [self.view addSubview:imgTempHeader];
 [self.view bringSubviewToFront:imgTempHeader];
Community
  • 1
  • 1
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
0

You should be creating the context in a way which uses the scale of the device:

UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);

Then when you display the image in the image view ensure that the content mode is set to prevent scaling.

Wain
  • 118,658
  • 15
  • 128
  • 151
0

My experience is with setting up imageViews in IB. I assume checkImage is an instance of UIImageView?

If you were displaying an image in a UIImageView and had only set the view mode to center in interface builder it would appear zoomed in if the image was large.

Have a look at this way to process your image first:

UIImage *newImage = [[UIImage alloc] initWithCGImage:myCGImageRef scale:myZoomSCale orientation:UIImageOrientationDown];

Of course you will need to give it a CGImageRef for your image. Over to you or somebody else for that.

Tim
  • 1,108
  • 13
  • 25