3

I m trying to take snap shot for ipad screen having 2 - 3 views. I m able to do that.

Now whats my problem is when I m in landscape mode, I just transformrotate one view with

CGAffineTransform transform;
transform = CGAffineTransformMakeRotation(M_PI/2);
imgPlayBoard.transform = transform;

Now, when I take the snap shot, then the image in image view appears portrait. Whats happening I am not able to get it. I am using following function to take a snapshot.

-(UIImage *)saveImage{

UIGraphicsBeginImageContext(imgPlayBoard.frame.size); 
[imgPlayBoard.layer renderInContext:UIGraphicsGetCurrentContext()];
[imagesView.layer renderInContext:UIGraphicsGetCurrentContext()];
[drawBoard.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * resultingImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIImageWriteToSavedPhotosAlbum(resultingImage, nil, nil, nil);
UIGraphicsEndImageContext();
return resultingImage;
}

And this is the image I m getting. The size of the image is same in the snap, but all apears is white.

DivineDesert
  • 6,924
  • 1
  • 29
  • 61

1 Answers1

3

Ok.. I found the solution myself. All was working fine. But Since I was transforming an image view, and then rendering it to the context, it was taking the original image of the imageview discarding the transformation. So What I did is all the three views I wanted in an image, I added them to an UIView and then took a snap shot of that uiview. This solved my issue. :) So now my function appears as below

-(UIImage *)saveImage{
    UIGraphicsBeginImageContext(imgPlayBoard.frame.size); 
    [containerView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * resultingImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext();
    return resultingImage;
}
DivineDesert
  • 6,924
  • 1
  • 29
  • 61