屏幕截图以IPad形式显示图像名称 [英] screenshots programmatically in IPad with the image name
问题描述
如何在Ipad中以编程方式保存屏幕截图,并从用户处获取图像名称?
how to save the screenshot programmatically in Ipad with image name taken from the user?
我找到了一个有效但不要求名称的代码片段图片。
i've found a snippet which works but doesn't asks for the name of the image.
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
还可以在相册中创建多个文件夹并以编程方式将图像保存在其中吗? / p>
Also is it possible to create multiple folders in photo albums and save the image in it programmatically??
推荐答案
将图像保存到相册时,无法指定名称。如果你想这样做,你必须将图像保存到应用程序的目录文件夹,然后构建一种向用户显示的方式,即他在内部保存的图像,并允许他删除,加载等。
You cannot specify a name when you save the image to the photo album. If you want to do that, you have to save the image to the app's directory folder and then build a way to show to the user, the images he has saved internally and allow him to delete, load, etc.
这是将PNG图像保存到磁盘的方法
This is how to save a PNG image to disk
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:myFileName];
NSData *imageData = UIImagePNGRepresentation(myImage);
[imageData writeToFile:appFile atomically:YES];
myImage是你的UIImage和
myFileName是你想要的名字
myImage is your UIImage and myFileName is the name you want
这篇关于屏幕截图以IPad形式显示图像名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!