Note: Using Monotouch. I have a directory called Images where I have all my PNG files. In my code I have the following
_imgMinusDark = UIImage.FromFile("images/MinusDark.png");
On the simulator it runs fine, on the phone it's null. I have the Images folder content (all the PNGs) in my MonoDevelop marked as Content in terms of Build Action.
What am I missing?
thanks
Add your Bundle's path to the full path using Path.Combine(bundlepath, "images/MinusDark.png")
Don't know if this is the case for Mono, but with standard UIKit the imageNamed method is case sensitive on the device and case insensitive on the simulator, which can lead to the exact problem you're describing.
Related
There is something very weird in my app after it has been released to the appstore.
Some of the UIImages i used are just missing and seen black from some reasons.
I have checked many times before in device and simulator and it appeared just fine.
Some notes:
I did drag the files and check COPY - the images are in the library for sure
Images DO appears in Copy Bundle Resources under Build Phases
I used these 2 lines in order to get the image:
[UIImage imageNamed:#"email_icon.png"] and [UIImage
imageNamed:#"facebook_icon"]
And i have just noticed that the extensions of the images are PNG not png - maybe is that the reason?
Appreciate your assistance!
Can you replicate this issue on your device? If not I'd recommend deleting the current version from your device and redeploying. You may have cached images on your device which are not allowing you from seeing the issue.
Secondly, yes, filenames on the device are case sensitive. Also make sure that you are properly naming the files and it is not simply a spelling mistake or change from an image name.
Per your line of code you are missing the file extension on the second image
[UIImage imageNamed:#"email_icon.png"] and [UIImage imageNamed:#"facebook_icon"] <-- what type of file is facebook_icon?
Can someone tell me the difference between these two means of loading an UIImageView?
iconView.image = [UIImage imageNamed:anIconFileName];
and
iconView.image = [UIImage imageWithContentsOfFile:anIconFileName];
I ran into a situation where when using the imageNamed method I had non-deterministic behavior loading the UIImageViews as subviews on a UIScrollView. The UIImages would load in the simulator, but not on a device using may iMac. But when I moved to my Mac Air everything worked as expected in both the simulator and the device? With further investigation, I found that it was nondeterministic when it worked. I was trying to load 5 UIImageViews and sometimes I would get 1 or maybe two. Getting any to load at all seemed to depend on the size of the *.png files I was trying to load.
When I changed with the imageWithContentsOfFile method everything worked as expected... reliably.
The UIImages didn't seem to be to large - about 100K each. Any thoughts would be helpful.
First thing - have you checked the name of image, because simulator load case insensitive image as well, while device will not load that.
imageNamed - this method takes file name.
imageWithContentsOfFile - this method take complete file path of that file name.
So above code which you have mentioned is dummy code or actual code, and if that is actual code then you need to be sure that with imageNamed you have to pass file name and with imageWithContentsOfFile you have to pass file path.
Check out this article for difference between these two method -
http://www.jorambarrez.be/blog/2012/04/19/ios-imagenamed-vs-imagewithcontentsoffile/
It's nothing to do with the UIScrollView just check the way you imported the images to Xcode. You should add files selecting the option:
Create groups for any added folders.
That way the folder will show in yellow (instead of blue) and imageNamed will work fine.
Interesting one this. I did do a bit Googling on the it but here we go. I have this png file. What I want to do is have it on my iPhone and send it to a server application on Windows. I use something like this:
NSString *filePath = [[NSBundle mainBundle] pathForResource:IconFile ofType:#"png"];
NSData *icon = [[NSData alloc ] initWithContentsOfFile:filePath];
NSLog(#"File path is %#",filePath);
NSLog(#" Bytes to send in Icon File %d",icon.length);
Now this works just fine when I am on the iPhone simulator. When I go to the device though the png format grows in size. For example I had one that was 2514 bytes and went up to 2652 bytes. When I transmit this file - its not able to be read by the Windows app.
So I assume that when a png file gets copied over in the resource bundle - it must get optimised or something. I can get round it by changing the extension to say .txt - then the file doesnt change.
Does anyone know why that is ? And can you prevent it being changed as I'd rather keep the correct extension. I have seen that png formats need to be converted when you get them from the iPhone but I dont know why this would happen when you upload one and it doesn't work in the simulator mode. Happens with both iPhone and iPad at iOS 5.
The modifying of the png images can be prevented in the build settings - under Packaging there is an option to compress PNG files:
Setting this to NO should solve your problem.
What happens is documented within this document: Viewing iPhone-Optimized PNGs
In short, Apple is using their patched version of pngcrush (note, this one differs from the one available through sourceforge).Their optimizing includes premultiplying the alpha values to speed up the loading process.
You may, as described by the linked document, revert this optimizing if needed (e.g. when reversing existing apps).
The easiest way to prevent this optimizing is to change/remove the file-extension when adding those images to your project.
PNG's are converted to a format "optimized for iPhone". Now this is just what I've read and I'm unsure what the optimization is and if it's actually an optimization, but that's what Apple has chosen to do. Maybe the iPhone GPU is quicker in loading their own format because of hardware support.
In any case, this happens to all PNG images when you deploy a project, and there is no way to prevent it that I know.
If your app downloads a PNG from a remote server this optimization will not occur and you can freely work with the file.
Yes, Apple optimizes all PNGs for display on the iPhone. For example, if you go to iOS .app in the Finder and view its "contents", you will see that all PNGs do not display correctly on Mac OS X.
The solution is to import your file as a "file" rather than an "image". One easy way to do this is to remove the extension then drag it into your project. Another way is to select the image in Xcode and change the File Type under the Identity and Type section in the assistant editor.
This particular stuff is getting me crazy :
Win [1365:707] Could not load the "Default.png" image referenced from a nib in the bundle with identifier "com.abc.acd"
How should I fix it and the error is only on device and not on simulator?
Open the XIB in question and make sure that none of your UIImageView's have their image property set to Default.png
Or, if you require the Default.png to be there, make sure that it exists in your Project files.
Just delete the app from the iphone and then clear all the target from the xcode.
Then run the application again
One possible reason is that the simulator finds the file because your Mac is formatted with case insensitive filesystem. That means that "Default.png", "default.png" and "DefAuLt.png" all counts as the same file.
However on the iPhone the filesystem is case sensitive which means that "Default.png", "default.png" and "DefAuLt.png" all counts as different files.
Therefore, be sure that your file actually is named "Default.png" and not "default.png" or something else.
You are getting this error because one of your NIBs refers to the image, and (for some reason) it isn't being packaged into your bundle correctly.
If you renamed your launch image (Default.png) to something different (eg MyAppBackground.png), then you'll have to find which NIB is referring to the original name and edit it to refer to the new name.
Capitalization counts. Make sure you have named the image Default.png (not default.png). The device is case-sensitive, but your Mac is not. If it works in the simulator but not on device, you probably have a capitalization problem.
The file must be included in the current build target. Select the image in your project hierarchy (Groups & Files), select "Get Info", and make sure that it's checked for the build target.
You might need to Clean (from the Build menu) the project and rebuild. Sometimes XCode just gets confused, especially if you've been moving or renaming images. Quitting & restarting XCode might help, too.
Check for duplicates of the app on the device. If you've changed the app's bundle ID, you might have this problem.
I'm working on sample project for learning core animation. I have problem with my device, I wrote simple project and it's conatins just one viewcontroller and this viewcontroller's view contains just two layer, each layer have .png image backgrounds (actually 700 x 700 px) and these images contains semi transparent content.
You can download example project from here
This project working perfectly on simulator but isn't working on Iphone. I have't seen any error or some thing like that. I have seen empty sreen on device.
Could someone give me suggestions about that please ?
Thank you
Your image file name is "Clouds1.png " but you load it:
[[UIImage imageNamed:#"clouds2.png"] CGImage];
Problem is that file system on iPhone is case sensitive and on MacOS is not. So you must be careful with file names.