Help on capturing screen

狂风中的少年 提交于 2019-12-12 01:29:03

问题


i want to take screenshots in landscape mode.

currently my below code takes screenshots in PORTRAIT mode.

also i want to store the images into the given location not in photo library..

how can i attain this...

thanks for any help

below is my code

UIGraphicsBeginImageContext(self.view.bounds.size) ;
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, self, nil, nil); 

回答1:


As far as I know there is no way to take screenshots in landscape mode. Images taken with the iPhone contain an information called imageOrientation which is then used to rotate an UIImageView displaying that image.

But you should be able to take an image in portrait mode and rotate it by 90 degree before saving it. I can't try it right now but the following should work:

Create a method for rotation and pass the UIImage as an argument.

CGSize size =  sizeOfImage;
 UIGraphicsBeginImageContext(size);

 CGContextRotateCTM(ctx, angleInRadians); // (M_PI/2) or (3M_PI/2) depending on left/right rotation

 CGContextDrawImage(UIGraphicsGetCurrentContext(),
  CGRectMake(0,0,size.width, size.height),
  image);

 UIImage *copy = UIGraphicsGetImageFromCurrentImageContext();

 UIGraphicsEndImageContext();

 return copy;

To store into a given location you can use NSData as I have answered on your other question ( Saving images to a given location )



来源:https://stackoverflow.com/questions/4130435/help-on-capturing-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!