将图像保存到Iphone照片库 [英] Saving images to Iphone photo library

查看:48
本文介绍了将图像保存到Iphone照片库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Objective-C完全陌生,我需要做一个应用程序,允许用户将壁纸下载到他的照片库中,墙纸视图"上有6个可下载的壁纸,所以我应该如何开始呢??我应该在哪里存放墙纸?将它们存储在Resources文件夹中是否可行?我当前的问题是我不知道如何加载它们并将它们写入照片库.

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? Where should I store the wallpapers? Is storing them in Resources folder viable? 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.

您可以通过UIButton表示它们,然后单击图像,将其保存到照片库中.

You can represent them via UIButton, and after click on image, save it to the photo library.

要加载资源中嵌入的图像,请执行以下操作:

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);

这篇关于将图像保存到Iphone照片库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆