重命名ipad中的图像,然后将该图像保存到应用程序包? [英] Renaming the images in ipad and then saving that image to app bundle?

查看:292
本文介绍了重命名ipad中的图像,然后将该图像保存到应用程序包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,其中我通过点击两个单独的操作按钮显示照片库和应用程序包中的图像。



现在我想要的是想要创建一个新的操作按钮,其目的是从照片库中选择一个图像,然后将该图像保存到我的应用程序包。



任何人都可以指导我向右

解决方案



p>我不认为你可以修改应用程序包一旦它在iPhone上。整个事情都是代码签名的,改变它会导致它不再运行。您可以尝试将图片保存到文档目录。



据我所知,一旦您的应用发布到App Store,您就无法在iPhone上重新打包。



我通常使用的方法是:


  1. 捆绑初始数据

  2. 有一个例程来检查
    是否存在版本文件在
    iPhone的文件系统启动时

  3. 如果该例程找不到
    当前版本的文件,则将
    所有数据复制到iPhone的
    文件系统

  4. 在我的应用程序中引用
    文件系统中的数据,而不是使用捆绑包路径

所以,本质上,你的bundle只是一个传递机制,一种方式来预加载文件系统你需要的东西。



将图片下载到文件夹



如何将UIImage保存到应用程序的捆绑包中?



UPDATE

   - (IBAction)saveImage:(UIImage *) image {
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
NSString * savedImagePath = [documentsDirectory stringByAppendingPathComponent:@savedImage.png];
NSData * imageData = UIImagePNGRepresentation(image); //根据需要改变
[imageData writeToFile:savedImagePath atomically:NO];
}


I am creating an app in which i am displaying images from photo library and app bundle by clicking on two separate action buttons.

Now what i want is that i want to create a new action button and its purpose will be to select an image from photo library and then save that image into my app bundle.

Can anyone guide me to right direction regarding this topic.

Thanks, Christy

解决方案

I don't think you can modify the application bundle once it's on the iPhone. The entire thing is code signed, and changing it would cause it to not run any more. You can try saving the image to documents directory.

So far as I know you cannot repackage the bundles on the iPhone once your app has been released to the App Store. So go the other way, and put the data from the bundle on the filesystem so you can change it at runtime.

My usual technique for this stuff is:

  1. bundle up the initial data
  2. have a routine that checks for the presence of a versioned file on the iPhone's filesystem at startup
  3. if that routine doesn't find the current version of the file, copy all the data into the iPhone's filesystem
  4. reference the data from the filesystem in my app, rather than using the bundle path

So, essentially your bundle is just a delivery mechanism, a way to preload the filesystem with the stuff you are going to need. Once it's on the filesystem you can change anything you wish.

References

Downloading image into bundle?

How to save a UIImage to the application's Bundle?

UPDATE

- (IBAction)saveImage:(UIImage *)image {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
NSData *imageData = UIImagePNGRepresentation(image);// Change according to your needs
[imageData writeToFile:savedImagePath atomically:NO];   
}

这篇关于重命名ipad中的图像,然后将该图像保存到应用程序包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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