简体   繁体   English

如何在iOS中将.jpeg / .tiff图像保存到设备库中

[英]How to save .jpeg/.tiff image into device gallery in iOS

I want to save my .jpeg and .tiff image with custom album into the gallery of device. 我想将带有自定义相册的.jpeg和.tiff图像保存到设备的图库中。

So I have refer this answer for saving an image with custom album into the gallery. 因此,我已将此答案用于将带有自定义相册的图像保存到图库中。

let myImage = UIImage.init(named: "image.tiff")
self.createAlbum(myImage!) //This method is taken from above linked answer

But it saves image into .jpg format always. 但是它总是将图像保存为.jpg格式。

Also I am trying to save image with default album using this answer . 我也试图使用此答案将图像保存为默认相册。 But it also saves image into .jpg format. 但这也将图像保存为.jpg格式。

I have read several posts here about saving image into gallery. 我在这里阅读了几篇有关将图片保存到图库的文章。 Unfortunately, it seems that there is not any "good" solution. 不幸的是,似乎没有任何“好的”解决方案。

When I saved my image into the document directory. 当我将图像保存到文档目录中时。 It saved with right format. 它以正确的格式保存。 But When I am trying to save this image into device gallery, then it always saves into .jpg format. 但是,当我尝试将此图像保存到设备库中时,它总是保存为.jpg格式。

Is there any other way to save image with custom name into the custom album in gallery..? 还有其他方法可以将带有自定义名称的图像保存到图库中的自定义相册中。

I want to save my .jpeg image and .tiff image into gallery of device. 我想将.jpeg图像和.tiff图像保存到设备的图库中。

Any help would be appreciated. 任何帮助,将不胜感激。

Can Save Image using following code 可以使用以下代码保存图像

import AssetsLibrary


let image = NSData(contentsOfURL: url)  
//or let image = UIImage.init(named: "image.tiff")

ALAssetsLibrary().writeImageDataToSavedPhotosAlbum(image, metadata: nil, completionBlock: { (assetURL: NSURL!, error: NSError!) -> Void in
        print(assetURL)
})

But apple stores it by default JPG Format. 但是Apple默认将其存储为JPG格式。 You are not able to change it. 您无法更改它。 It Totally managed by Apple. 它完全由Apple管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM