I am using images in my app which need to have transparency. They are currently .png files, but converting them to .jp2 (JPEG 2000) reduces the file size considerably. I added them to the Xcode project, but they are not loading when I run the app. Does this mean Xcode/Objective C does not support .jp2 files?
You have there files supported by apple, and i can't see jp2. So my answer is: no, jp2 is not supported.
Here you can find what images are supported by iOS UIImage. .jp2 format isn't on that list. So it's not supported.
Related
I have to convert a DICOM image into any supportable format for UIImageView such as JPG, PNG, etc. Are there any frameworks to implement in iOS for iPad?
I found ITK useful to do this but still I don't know how use ITK to implement this.
The only opensource DICOM library I know of is Imebra; it claims support for Windows and OSX only, but as a C++ library I can't foresee any major difficulties with porting it to iOS.
There is one open source Lib "GDCM", you can check this ANS How to display DICOM files in a view on iPhone.
Even i have not tried my self, but seems to be right way to go.
By the way, have you tried what "Benjamin Mayo" answered ? was imebra usful to you ?
Xcode optimizes png images so they are loaded faster, but is this also recommended for other image resources that are not for buttons and UI (Photos for example)?
Or is it a standard to have UI images as png and "photos" as JPEG?
What is the best practice here?
The best practice is to use PNG files as often as possible when using images within your app. iOS and Xcode load and display PNGs quickest as opposed to any other type of format. If given a choice, go with PNG.
When you use any other file type (or if you load a non-optimized PNG files), your iPhone has to do the byte-swapping and alpha premultiplication at load-time (and possibly re-do the alpha multiplication at display time). Your application basically has to do the same processing that Xcode does, but it's doing it at run-time instead of at build-time. This is going to cost you both in terms of processor cycles and memory overhead. One of the reasons why Mobile Safari is the biggest memory hog of the built-in iPhone applications is because the images it has to load in order to display web-pages are all non-optimized images, mostly JPEGs. Since JPEG is a compressed format, it has the added extra step of having to decompress the image into memory before it can do the premultiplication and byte-swapping.
For what it's worth, Apple recommends using the PNG format for images. There's a lot more information on this topic in this Apple documentation.
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.
Does the ImageMagick for iOS support converting jpeg images to GIF? How to do that?
GIFS are "inherently supported in ImageMagick", according to comments here.
This article describes how to export an animated GIF from UIImage source using ImageMagick on iOS that you can use as a starting point.
MagickWand *mw = NewMagickWand();
MagickSetFormat(mw, "gif");
Apparently, ImageMagick does support GIF creation on iOS, even though their website clearly states it only supports png, jpeg and tiff on iOS. I haven't found any source of this worth linking and the other link mentioned below is no longer existing, so good luck with that.
Is it possible to set an iPhone Xcode project to skip the 'CompressResources' build step?
Specifically, I want to skip the stage where it runs pngcrush on all of my .png files, many of which don't survive the experience in a form which my app can read.
Edit: the version of pngcrush used creates png files which contain a non-standard 'mandatory, private' chunk which explicitly prevents decoding. I've modified my png reader to handle these files, but I'd still like a per-project method of skipping this step. One of the other side effects of pngcrush is that it doesn't save the colour value of transparent pixels, so alpha-ed textures show fringing at smaller mip levels.
The iphone png format is described here: https://web.archive.org/web/20110519164905/http://modmyi.com/wiki/index.php/Iphone_PNG_images. In short,
Skip the CgBI chunk
Skip the zlib headers
Swap BGR to RGB channel order
Edit: It appears it also premultiplies the alpha, so:
Divide by alpha
You can add "IPHONE_OPTIMIZE_OPTIONS=-skip-PNGs" to your project settings to prevent the png mangling, but be careful with it, you might need to optimize the icon and Default.png separately then.
The iphoneos-optimize script converts PNG files into a nonstandard format that is optimized for display on the iPhone. The script will convert any files with the png extension that it finds inside your app bundle.
I had a similar problem, and solved it by giving my file the extension _png (i.e., prefixed an underscore). iphoneos-optimize ignored it and left it a regular PNG file. If you can deal with it that way, it's probably a lot safer than mucking about with the build scripts.
Open build settings
Under "packaging" choose Compress PNG files
Choose "NO"
If you look at the build output you'll see that the CompressResources step runs the script /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/iphoneos-optimize. This appears to be just a shell script that runs pngcrush and compiles plists into binary format. You could probably modify this script to not run pngcrush.
Note that someone in this thread noticed that if they did not run their icon file through pngcrush it wasn't showing up on the phone.
Interestingly, the version of pngcrush in the directory of the script has a -iphone argument. Anybody know if this is standard or something Apple just ships with their build of it?
That might be another issue all together. In many cases the problem has to do with naming and can be solved very easily.
read this:
http://cocoapi.wordpress.com/2009/03/22/iphone-images-not-appearing-in-real-iphone-this-is-why/