0

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

Vipin
  • 4,718
  • 12
  • 54
  • 81
  • do you want paths or how to take image from the displaying one.. – ajay Apr 26 '11 at 05:02
  • Thanks for responding,i have to select images from the existing images in photo library and yes for that purpose i must know the url of the images and i know them .now i want to save these images to app bundle ,please tell how to save in app bundle using urls – Vipin Apr 26 '11 at 05:08

2 Answers2

0

You can make an NSData from the image you are picking from your photo library by using this -

NSData *imageData = UIImageJPEGRepresentation (UIImage *image,CGFloat compressionQuality);

then call

[imageData writeToFile:imgPath atomically:YES];

Here imgPath is the path for TMP dirextory where you want to write the file, get it as -

NSString *filename = @"a.png";

NSString *uniquePath = [TMP stringByAppendingPathComponent:filename];

and TMP is an enum

#define TMP NSTemporaryDirectory()
saadnib
  • 11,145
  • 2
  • 33
  • 54
  • mine is an speechrecognition app when i speak "rose" an image of rose is being displayed and in my library i have image of rose ,now what i want is this image of rose is being saved to app bundle as "ROSE.png".will this code of yours will serve that purpose to me.in that NString *filename i have to give the text entered in my text field to save that image as the desired name.Is it so? – Vipin Apr 26 '11 at 05:15
  • @Christina you cann't save files to app bundle because the app bundle is signed the with SSL certificate, you cann't change it. You can write your file to TMP or document directory. The above code writes file to TMP. If you want how to get document directory path then let me know? – saadnib Apr 26 '11 at 05:25
  • @saadnib -yes,i want to know how to get document directory path. – Vipin Apr 26 '11 at 05:32
  • you can get it as, i m using it for getting database path - NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [documentPaths objectAtIndex:0]; databasePath = [[documentsDir stringByAppendingPathComponent:databaseName] retain]; – saadnib Apr 26 '11 at 05:35
  • Thanks a lot saadnib for this,now can u help me with playing movie clip in my app – Vipin Apr 26 '11 at 05:39
  • To play movie clip you can follow the tutorail - http://mobile.tutsplus.com/tutorials/iphone/iphone-sdk-playing-video-with-the-mediaplayer-framework/ – saadnib Apr 26 '11 at 05:59
  • can u tell me how to add images in documents directory – Vipin Apr 26 '11 at 05:59
  • You should read AVFoundation framework of apple for this.Try this from developer.apple.com. – Sandeep Singh Apr 26 '11 at 06:02
  • NSString *imagePath = [[documentsDir stringByAppendingPathComponent:fileName] retain]; by using this you can get the path where you can add image, then in my answer make a NSData from that image and call writeToFile on NSData. – saadnib Apr 26 '11 at 06:04
0

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];   
}
Community
  • 1
  • 1
visakh7
  • 26,380
  • 8
  • 55
  • 69