UIImagePickerController returned image woes - iphone

I have a UIImagePickerController that lets the user pick an image from their library, edit it, and then save the product out to disk. Before it saves, however, I need to update a UIImageView to hold the edited photo. But when I go to set the UIImageView's image property, the program crashes. It still can save to disk.
The UIImageView is an IBOutlet and the dimensions are 88x88, if anybody cares.
I can reproduce this issue on a device (iPhone 3GS running iOS4) and in the simulator (iOS 4).

Don't you know what the error is? Especially in iOS4 you should see an entire stack trace in your log.
Most likely culprit would be a bad Interface Builder link... from there you should do retain count on your actual UIImage to see where it is when you assign it to the ImageView...
Anything after that, I suspect, would be application specific.

Related

iphone iOS memoryWarning handle for navigationController and ALAssetlibrary

I do resizing for FullReoslutionImage, so it may introduce memorywarning from iOS.
When I recieved memorywarning, it sometimes unload my ALassetlibrary for album, and it introduce crash when users choose image.
How could I prevent this kind of problem, how to unload my other resources and other viewController?
On other hand, when viewcontroller is unloaded, when I go back to this view , it seems introduce crash. How to prevent it ?
Thank you very much!!
I found it was reduced much when I use 3rd party JPEG decode library to decode&resize it under 2048x2048 UIImage. So the memory wanring happen so often may be caused by creating UIImage larger than 2Kx2K.
Hope this helps.

UITextView BackGround image iphone

I m working on note app. In which i m creating view like iPhone notes.
First i took a scroll view and then one image view. After that I m creating a UITextView dynamically... I set the background image of UITextView..
using this code
textView = [[UITextView alloc]initWithFrame:CGRectMake(0,30,320,400)];
textView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: #"lines.png"]];
Its working perfect in simulator. but when i run my app on device then UITextView's background doesn't display... means it doesn't display lines...
My image size is 365x45...
Can anybody help me why this happen???? Where is the problem???
thanks!!
I had a similar problem once and got grey hair over it. :)
Double check whether your background image file (the .png or whatever) is still boundled with your app. Check this with the project or tartet settings when you have multiple targets.
In my case the file was included in the project but not in the boundle. For reasons that I never understood it was part of the bounle installed on the simulator. It was even there when I deleted the app manually from the simulator's file system. Re-launched the app in the simulator and it was there again.
But when I checked the content of the boundles that where sent to debug devices or the store, the image file was missing.
The same problem may occour to you.
I never used that method. What I do is I put an invisible UITextView over the UIImageView

Images showing in simulator but not on the iPhone device

So when I run the application from the device the pictures show up and everything works great. However, when I move to the device I run in about 10 out of 38 pictures that don't show up. I am pulling the names for the images from an sqlite database and I already checked and the names are correct, case and everything. I checked the bundle and the images are correctly in there.
Does memory play into effect in this? I am not really sure what else could cause this to happen??
Thanks!
Solution:
The files somehow were not saved properly and were unable to be opened by say photoshop or paint even. So with the files not being able to be open they weren't showing up... Thanks for the help everyone!
First thing to check is the case of the strings you're using to refer to the resources. The iPhone is case sensitive, but the simulator is not.
Oops, just seen that you checked the case. Better log all your UIImage creation calls then!
The simulator accepts a wider range of image formats. Sometimes you had a specific file type that the device cannot display. Double check the 10 files looking for some difference from the others ones.
Yes, memory absolutely plays into this. Check your UIImage creation calls and make sure they dont return empty. Also, check to see if youre getting memory warnings in the console window.
Generally, if in-memory size was the culprit, your application would crash with a low memory error on the device. However, it seems like the images just don't display.
One other thing that can be going wrong is the size of the images. UIViews on the iPhone can only have dimensions smaller than the maximum texture size supported by the GPU. Apple states that this is 1024 x 1024, but I've found it to be more like 2048 x 2048 on even the original model iPhone. You may be creating a view for some of these images that exceeds this size in one dimension, but your Mac has a larger maximum texture size on its GPU and so it displays fine in the Simulator.
Apparently the iPhone caches the launch screens. So in my case, I had to reboot my iPhone before being able to see the image.

cell.imageView is working on Simulator but not on Device

Table view cell imageView is working on the simulator but not on the device..
Some things I have checked.
I have not changed anything in the code.
Image is added to the project and in same folder.
I have one more cell image which is working fine.
Thank you in advance.
Iphone device is case sensitive ... and simulator is not..
Make sure you check the case of the name used in your +[UIImage imageNamed:] calls. These are case-sensitive on the device, but not always on the sim. That's the most common cause of missing images. If that isn't the source, put a breakpoint where you're assigning the image, and check all teh variables.

How does UIImage work in low-memory situations?

According to the UIImage documentation:
In low-memory situations, image data may be purged from a UIImage object to free up memory on the system.
Does anyone know how this works? It appears that this process is completely transparent and will occur in the background with no input from me, but I can't find any definitive documentation one way or the other.
Second, will this data-purge occur when the image is not loaded by me? (I'm getting the image from UIImagePicker).
Here's the situation: I'm taking a picture with the UIImagePickerController and and immediately taking that image and sending it to a new UIViewController for display. Sending the raw image to the new controller crashes my app with memory warnings about 30% of the time. Resizing the image takes a few moments, time that I'd rather not spend if there's a 3rd option available to me.
I think this is the answer. In the documentation for initWithContentsOfFile: it says:
This method loads the image data into memory and marks it as purgeable. If the data is purged and needs to be reloaded, the image object loads that data again from the specified path.
None of the other methods in UIImage mention purging, so it appears that initializing a new image from a file is the only way to get this low memory behavior.
In answer to your second question: Save it to a file, and then use:
[NSData dataWithContentsOfMappedFile:]
to do the resizing. Using a files as intermediates, is rather slow though.