【问题标题】:screenshots programmatically in IPad with the image name以编程方式在 IPad 中使用图像名称截取屏幕截图
【发布时间】:2010-11-08 09:20:00
【问题描述】:

如何以编程方式将屏幕截图保存在 Ipad 中,图片名称取自用户?

我找到了一个 sn-p,它可以工作但不询问图像的名称。

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

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

【问题讨论】:

    标签: iphone ipad


    【解决方案1】:

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

    这是将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 是你想要的名字

    【讨论】:

    • 你能指导我怎么做吗??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    相关资源
    最近更新 更多