Raf*_*eeJ 3 screenshot uiimage ios
我已经看了很多关于如何以编程方式截取屏幕的教程,我没有任何运气:(请有人能详细告诉我,因为我现在只编写了一段时间!谢谢!
iNo*_*oob 14
你可以用它UIGraphicsBeginImageContext来达到这个目的.
例如 :
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage*theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData*theImageData = UIImageJPEGRepresentation(theImage, 1.0 ); //you can use PNG too
[theImageData writeToFile:@"example.jpeg" atomically:YES];
Run Code Online (Sandbox Code Playgroud)
这里
1.首先,我采用图像上下文,我已经将其作为myViewwebview,您可以提供任何您想要的内容.这将获取可在屏幕上看到的webview图像.
2使用UIGraphicsGetImageFromCurrentImageContext()i将我的webview的屏幕截图转换为图像.
3.通过使用UIGraphicsEndImageContext()我要求它结束上下文.
4.我保存图像到NSData,因为我不得不邮件的截图.NSData如果它用于发送或保存,保持它似乎是一个很好的选择.
编辑:要将其添加到相机胶卷,您需要写:
UIImageWriteToSavedPhotosAlbum(theImage,nil,NULL,NULL); 后 UIGraphicsEndImageContext();
| 归档时间: |
|
| 查看次数: |
7577 次 |
| 最近记录: |