2010-11-08 66 views
2

如何在Ipad中以编程方式保存屏幕截图,并从用户处获取图片名称?在图片名称中以编程方式在iPad中截图

我发现了一个可以正常工作但不要求图像名称的代码片段。

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

也有可能在相册中创建多个文件夹,并以编程方式保存图像?

回答

2

将图像保存到相册时无法指定名称。如果你想这样做,你必须将图像保存到应用程序的目录文件夹,然后构建一种方式向用户展示他内部保存的图像并允许他删除,加载等。

This如何在一个PNG图像保存到磁盘

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的是你想要

+0

的名字,你可以指导我该怎么办呢? – Hisenberg 2010-12-06 06:04:13

+0

我编辑了解决方案的答案。 – SpaceDog 2010-12-06 16:58:47

相关问题