Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 01-21-2010, 08:26 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 30
Unhappy Storing ImagePickerController Dictionary for use in other action

I want to open an image from the cameraroll and resize it so the user can get a preview of all the changes he's applying to the image without the image taking up too much memory. After the user finishes doing whatever he has to do with the image I allow the user to save the image. When the image is saved, the full sized image is retrieved from the UIImagePickerOriginalImage key and the changes are applied to the full image as well. But there is one big issue.

I can't seem to be able to store the ImagePickerController's Dictionary for use in the save IBAction.

Here's some code to explain my issue :

This is the part where the image is loaded to imaget (the preview's UIImage)
and where the NSDictionary is being stored in a variable I declared before (NSDictionary *dict; )

Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)editInfo
	{
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
	dict = editInfo;
	UIImage *imaget = [dict objectForKey:@"UIImagePickerControllerOriginalImage"];
//image get resized
//image gets loaded into the preview
}
Here everything goes smoothly, the image loads into the preview.
Everything that happens between this action and where the user saves is irrelevant as it all works and used to work before.

But here's where the big problem arrises :
In my Save Action I want to call the Original image again from the "dict" NSDictionary, but this fails miserably eventually crashing the app.

Code:
UIImage *imaget = [dict objectForKey:@"UIImagePickerControllerOriginalImage"];
//perform all changes
//save the image
The issue is in the above code and not in any other as I simplified the app until basically only the above code remained and the problem still persisted.

Can anyone help me? Can this NSDictionary be stored into a variable for later use?
ykrsdn is offline   Reply With Quote
Old 01-21-2010, 09:29 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 96
Default

Basically what is happening to you is you are assigning the var dict to point to the nsdictionary but not telling the system to retain it. When editDict goes out of scope the dictionary you are referencing is deallocated. You need to retain it.


What to do will depend on how you created the var "dict".

If you simply declared the var at the class level then:

dict = [editInfo retain];


If you also created a property for it with (nonatomic, retain) then
self.dict = editInfo (or [self setDict:editInfo] is the same thing)
shan is offline   Reply With Quote
Old 01-21-2010, 09:32 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 30
Default

Quote:
Originally Posted by shan View Post
Basically what is happening to you is you are assigning the var dict to point to the nsdictionary but not telling the system to retain it. When editDict goes out of scope the dictionary you are referencing is deallocated. You need to retain it.


What to do will depend on how you created the var "dict".

If you simply declared the var at the class level then:

dict = [editInfo retain];


If you also created a property for it with (nonatomic, retain) then
self.dict = editInfo (or [self setDict:editInfo] is the same thing)
Oh, thanks! I forgot to retain the variable. Now that you mention it, it makes sense.
ykrsdn is offline   Reply With Quote
Reply

Bookmarks

Tags
imagepicker, key, nsdictionary, uiimage, uiimagepickercontroller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 263
17 members and 246 guests
14DEV, @sandris, ADY, ArtieFufkin10, bookesp, ckgni, Dani77, DarkAn, HemiMG, iDifferent, jakerocheleau, JasonR, prchn4christ, Rudy, Speed, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:49 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0