捕获屏幕帮助 [英] Help on capturing screen

查看:55
本文介绍了捕获屏幕帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在横向模式下截图.

i want to take screenshots in landscape mode.

目前,我的下面代码在PORTRAIT模式下拍摄屏幕截图.

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...

感谢您的帮助

下面是我的代码

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

推荐答案

据我所知,无法以横向模式拍摄屏幕截图.用iPhone拍摄的图像包含名为imageOrientation的信息,该信息随后用于旋转显示该图像的UIImageView.

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.

但是您应该能够以纵向模式拍摄图像并将其旋转90度,然后再保存.我现在无法尝试,但以下方法应该可以工作:

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:

创建一个旋转方法,并将UIImage作为参数传递.

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;

要存储到给定位置,您可以使用NSData,就像我在其他问题上回答的那样(

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

这篇关于捕获屏幕帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆