从URL Phonegap Iphone保存图像 [英] Save image from URL Phonegap Iphone

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

问题描述

我google了很多,但我找不到一个解决方案。



我需要一些方法来保存网络上的图片在我的应用程序。像一个函数,其中我可以只是把url,它会下载它:



ie

  DownloadPhoto('http://www.myserver.com/myphoto.jpg'); 

是否有这样的东西?

解决方案

这应该做的

   - (void)downloadPhoto:(NSString *)urlToDownloadFrom 
{
//下载图片。现在downloadeImg有你想要的img。
UIImage * downloadedImg = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:urlToDownloadFrom]]];

UIImageWriteToSavedPhotosAlbum(downloadedImg,self,
@selector(savedPhotoImage:didFinishSavingWithError:contextInfo :),NULL);
//将图像保存到您的Photos.app/directory并调用savedPhotoImage fucn。不清楚如果你实际需要这个功能。

}

   - (void)savedPhotoImage:(UIImage *)imagedidFinishSavingWithError:(NSError *)errorcontextInfo:(void *)contextInfo 
{
}
pre>

I googled a lot, but I couldnt find a solution.

I need some way to save pictures from the web on my application. Like a function, where I can just put the url and it will download it:

i.e

DownloadPhoto('http://www.myserver.com/myphoto.jpg');

Is there something like this?

解决方案

This should do the trick

- (void)downloadPhoto:(NSString*)urlToDownloadFrom
{
    // Download the image. now downloadeImg has the img you want.
    UIImage *downloadedImg = [UIImage imageWithData: [NSData dataWithContentsOfURL:
                               [NSURL URLWithString: urlToDownloadFrom]]];

    UIImageWriteToSavedPhotosAlbum(downloadedImg,self,
                         @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:),NULL);
   // saves the image into your Photos.app/directory and calls the savedPhotoImage fucn. Am unclear if you actually needed this function. 

}

-(void)savedPhotoImage:(UIImage *)imagedidFinishSavingWithError:(NSError *)errorcontextInfo:(void *)contextInfo
{
}

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

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