简体   繁体   English

将图像保存到Iphone照片库

[英]Saving images to Iphone photo library

I am totally new to objective-c and I need to do an app which allows user to download wallpapers to his photo library, I have 6 wallpapers on the "wallpaper view" that are downloadable, so how should I start this off? 我对objective-c完全不熟悉,我需要做一个允许用户将壁纸下载到他的照片库的应用程序,我在“壁纸视图”上有6个可下载的壁纸,所以我该如何开始呢? Where should I store the wallpapers? 我应该在哪里存储壁纸? Is storing them in Resources folder viable? 将它们存储在Resources文件夹中是否可行? My current issue is that I have no idea how to load them and write them to the photo library. 我目前的问题是我不知道如何加载它们并将它们写入照片库。

If the images are unchangeable you can embed them in resource folder, otherwise you can host them on server, and reload them at every app relaunch. 如果图像不可更改,您可以将它们嵌入资源文件夹中,否则您可以将它们托管在服务器上,并在每次重新启动应用程序时重新加载它们。

You can represent them via UIButton, and after click on image, save it to the photo library. 您可以通过UIButton表示它们,点击图像后,将其保存到照片库。

For loading images that are embedded in resource use: 用于加载嵌入资源使用的图像:

UIImage* img = [UIImage imageNamed:@"imageName.png"];

Or you could get images from internet, by: 或者您可以通过以下方式从互联网获取图像:

UIImage* img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://yoursite.com/image.png"]]];

For creating button, with image, use: 要创建按钮,使用图像,请使用:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
btn.frame = CGRectMake(40, 140, 240, 30);
[btn addTarget:self action:@selector(downloadImage:) forControlEvents:UIControlEventTouchUpInside];
[btn setImage:img forState:UIControlStateNormal];
[self.view addSubview:btn];

And when you have image, you can save it to the photo library with: 当您有图像时,可以将其保存到照片库中:

UIImageWriteToSavedPhotosAlbum(img, nil,nil,nil);

You save photos to the library with 您可以将照片保存到库中

void UIImageWriteToSavedPhotosAlbum (
    UIImage  *image,
    id       completionTarget,
    SEL      completionSelector,
    void     *contextInfo
);

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

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