Giving a JPEG image a .PNG ext in file name? (Xcode) - ios

I know you can inspect an image to determine what its file format is, but just supposing you append .png to the name of an image file when it is in fact in JPEG format, are there any possible issues that can arise as a result or does it not matter to Xcode what you call it, once you have .png or .jpeg at the end of the image file name?

Yes. This will cause you problems. They are completely different formats. Although you are usually able to freely rename image extensions on your computer, and they remain openable in image editors, this is only because the editors don't necessarily rely on the extension for the format.
However, in Xcode, although it may not cause you problems initially... somewhere down the line, it'll come back to bite you - I guarantee it.
I have no idea why you'd want to do such a thing in the first place!

Related

How to convert jpg or png to svg in iOS?

I like to convert an .jpg or .png file to an .svg format that can be displayed in UIImageView. Is there a way to do this in Objective-C?
You shouldn't use SVG images in Xcode:
it is recommended that you use PNG or JPEG files for most images in your app. Image objects are optimized for reading and displaying both formats, and those formats offer better performance than most other image formats. Because the PNG format is lossless, it is especially recommended for the images you use in your app’s interface.
Also, there's an SVGKit that according to many devs is buggy so use it at your own risk.
SVG is an XML-based vector and in Xcode you can also use vectors but using a PDF format and follow this tutorial.
In a nutshell:
Generate PDFs With the #1x Asset (During compile time it will generate #2 and #3)
Set the Scale Factors to Single Vector:
Drag and Drop Your PDF Into the All, Universal Section
Refer to Your Image by Its Name, Like for any PNG File
[UIImage imageNamed:#”Home”]
Also, stackoverflow (perhaps) related answer
To convert PNG to SVG (Which is a very sensible and valid thing to do) you need an app or library called a "tracer". It will trace the outlines of shapes, gradients, etc and convert them into vector representations.
For simple cases, this is easy for a computer to do; for complex cases (e.g. gradients), this is a very hard AI / Computer-Vision problem and you'd need to spend $$$ on high-end coding solutions and/or find PhD-level research that solves the problem!
A free tracer that does a very good job is built-in to Inkscape (open-source) - google "inkscape trace" for tutorials on how to use it, and to generate a .svg file that you can use. This is a manual process.
To use this in-app, you need to find a tracing library for iOS. The libraries that Inkscape uses are all open-source, so you could try converting them to iOS - they're written in C, so it could be quite easy.

Why XCode changes images in xcassets folder while packing?

I optimized and put compressed images into Images.xcassets
When I build the package and look into the contents of it, I see that all of the images are modified by XCode (build tools etc..) and for example Default-568h#2x.png (218KB) becomes LaunchImage-568h#2x.png(455KB)
This makes it impossible for me to put optimized images.
What am I doing wrong here?
Your issues is most likely premultiplied alpha channel. I ran into this same issue when designing my game engine and it was relatively painless to fix.
Last I knew there is no option to disable premultiplied alpha channels for the Xcode bundle.However, Xcode comes bundled with a textureool which can be used at build time to format your images into another format that does not suffer this same optimization. Since my code focuses on sending texture data to OpenGL i used the powerVR format PVRTC. However, you're free to utilizes whatever format you like.
If you decide to go this route you can add a build target to your project which converts all png files into which ever format you prefer.

Why don't asset catalogs enforce me using the right size images?

I originally saw the new asset catalog feature in XCode5 and was pretty pleased - no more messing about with dozens of different versions of the files, I thought.
But it doesn't seem to actually make anything any easier. It still doesn't simply tell me "you need an image of 114x114 pixels here". And it seemingly will let me specify any image of any size for each icon variant. Does it magically resize my images, or will things just break, if I supply a 50x50 icon when it expects a 72x72 one?
All I want is a list of "these are the exact files you need to supply" and "these are the ones you didn't supply yet". Perhaps I am misunderstanding how this is to be used, because a utility which won't complain about being given bad data seems worse to me than no utility at all!
If what you want is, as you said: a list of "these are the exact files you need to supply" and "these are the ones you didn't supply yet", maybe you can try the the "Don't use asset catalogues" option of the drop-down menu of App Icons or Launch Images.
Here it is what it will look like then:

iPad: PNG Crush error

I am trying port my iPad project to latest iPad 2. I installed iOS 4.3 SDK with Xcode 4.0. When i try to build my project, i'm getting the following error. I don't know why am i getting this error. Could someone help me to resolve this build error?
While reading /Users/username/Desktop/iPAD/MyProject/trunk/Resourses/images/top_bar.png pngcrush caught libpng error:
Not a PNG file..
Could not find file: /Users/username/Library/Developer/Xcode/DerivedData/Project-fmhveawksgdtnraclfizuhrekmzi/Build/Products/Debug-iphoneos/MyApp-Upgraded.app/top_bar.png
I had the same problem, but it wasn't because of a corrupted png : it was because two PNG files had the same filename in different directories of my source tree. What was peculiar was that the errors (I had 4 files which had "twins") were not identical from one build to another. On one run I had errors on all files, on the other only on some of them.
Did you check whether the file Users/kavapanga/Desktop/iPAD/ALN II 3 latest 2/trunk/Resourses/images/CS_logo_for_top_bar.png exists? Also check if it is infact a PNG file. Right click on the file and do a Get Info to check if the file has any other extension and is marked as hide extension. If you are not sure of the format of the file, opening the file and save it as a PNG file again should work ,most of the time.
I had the same problem.
How to fix : Open up image with Preview -> File > Export > Format change to PNG and you are done !!
There is no issues with image or Xcode. The issue, which creating that image from photoshop, is whether that image is interlaced or not interlaced. While saving your image in photoshop you will get one option for that.
Check out this link for more info:
Build app with Xcode 4 - it always show some error about PNG image
not interlaced: You should use image which is not interlaced. This is the original png image.
interlaced: This option is suitable for the image which are getting downloaded from web. Specifically saying, this is used when you require to reduce image load time. What this option internally does is, it will create a .png file but with lower clarity and lower dpi like a normal jpeg image. That's why such images are having property that it is jpeg image.
Hope this will help you all.
Enjoy Coding :)
I got this error when I moved images around in the project's folder, to an "Images" folder.
Turns out my "Copy Resources" build phase contained the steps both to copy the files from their new, correct folder - and from the previous folder where they were stored. Removing the outdated build steps fixed the errors.
Another reason pngcrush considers PNG files to not really be PNG files is if you accidentally export them with layers intact. If you inspect the file in Finder, look around the More Info area (Dimensions, Color Space, etc.) for an item called "Layers"
It might say something like:
Layer 68, Title Banner, Group 26
This happens when designers sometimes Save As PNG instead of exporting for web/mobile. And it completely destroys libpng (and thus pngcrush).
The fix is to properly export the PNG, or open the PNG yourself and re-export it as a "flat" PNG.
This can be caused by incompatible PNG file format. You will need the "Color profile" for your png file to make it work in Xcode.
First off, check the info for your file.
While this is a valid PNG file, this is NOT the format that Xcode can take. You will need the following PNG format:
To convert your PNG file to a format that Xcode can take. You can use Preview to export the file.
Had this issue as well. The PNG existed and wasn't corrupt.
Solved it by:
R-click the image in xcode, select "Delete"
Remove reference only (don't actually trash the file)
Drag n' drop it back into xcode (in-place) making sure you select the correct targets
I had this problem and found there was a problem with the png. I remade it and worked fine.
I had the same problem. Even though the file extension may be png the file may still be something else. And 'get info' shows what ever the file extension is I think. Open up the file in preview and go to tools -> show inspector -> File tab. Here you should be able to see the actual file type.
I had this error and it was actually totally unrelated to the png's it was erroring on. The actual problem was I had two files with the same name in my project (I had drag'n'dropped a newer version of a 3rd party class assuming it would replace the older version).
I removed the reference to the duplicate file and that solved the build errors.
Problem Solved
I got the same problem couple of time in development but today i found that there are two solutions and their possibilities, here is this
Problem Solved#1: If you Create or your designer create the design which they saved the pnd from adobe illustrator then its got the problem if you create by yourself just copy all the AI artwork to the photoshop or if your designer create it then just tell them to import the illustrator format to the photoshop and send the pnd.
Problem Solved#2: select the image right click the image->get Info and check that it is in correct .png format or not if its not then just edit .png extension.
Just Enjoy.
I get the same error when I tried to copy my project folder and run the project. The project in the original folder didn't have that problem.
Deleting the copy and making a new copy of the folder solved my problem.
Error:
While reading /Volumes/Mac OS/RDC/Workpot/RestApp/RestApp/default1024_768.png pngcrush caught
libpng error: Not a PNG file..
Solution:
I opened "default1024_768" file in PaintBrush tool and saveAs PNG file with same name.
Replaced the Icon file in Xcode project --> Clean --> Build.
That's All its work like charm
Hope this will help someone.
I have this bug quite often. if you 100% sure that your png is there and is correct then just simply recompile the project, if does not work - recompile again and again, and sometimes it will start working ;-) that's a bug in Xcode that was there for long time (since Xcode3).

Problem with showing some JPG files in Delphi

i have tried to open some JPEG files in Delphi with TImage component. i also added the Jpeg unit. i can open most of jpg files and there is no problem.
but when i try to open some JPGs, the program just throw an exception.
i also tried to load that images in design mode, but there is some problem. in design mode the exception is:
Access violation at address 402672A1 in module 'vcljpeg70.bpl'. Write of address 08E84000
Why i cannot open that JPGs? they are not corrupted. i checked them in some tools like savantools EXIF viewer.
here is the URL of one of that images:
http://xs842.xs.to/xs842/09340/backpic435.jpg
Thanks so much
PS:
My Delphi version is 7. Borland Delphi 7
The reason you may be encountering this problem is due to the file type. Delphi has issues displaying JPEG images that have been encoded using CMYK, rather than the default RGB encoding. CMYK is a format that is generally used for Print design, try and always encode your images to RGB format to avoid this issue with Delphi.
Patch for Delphi jpeg.dcu
Bye.
Interesting. Neither Internet Explorer nor Google Chrome will display that JPEG image you linked to. I do not get 404 Not Found errors, I simply get an image placeholder, indicating that the image could not be opened/displayed correctly.
FireFox does display the image.
Are you certain that there is not something fishy, or at least slightly unusual, about the JPG files involved?
UPDATE: The file linked to in the question opens in PaintShop Pro (an old version 6.0 installation) - if I then simply re-save as a Standard Encoding JPEG, IE and Chrome both display the newly saved image as I'd expect. There would definitely appear to be something a bit "odd-ball" about the encoding of the original JPEG that some JPEG apps can handle but not all, including some "major players", not just Delphi. :)
Check out the Free Image library for alternative JPEG support in Delphi if the native one has problems. Free Image is an open source lib that lets you work with JPEG/PNG/... from Delphi/BCB/and others. Very nice library IMHO.
http://freeimage.sourceforge.net/
I've looked at the file with a hex editor, and found 3 JFIF headers. After extracting each part, I found 2 thumbnails and an image. Nothing special, because embedded thumbnails seem to be part of the EXIF2 standard.
The thumbnails themselves load fine in Delphi, and converting the file to something readable can be done with almost every piece of software that I've tried.
Anyway, this page will give you very detailed information about the picture, and what headers are inside (just paste the url of your image in the textbox):
http://www.monster-submit.com/resources/jpeganalyzer/
I get the same error. This appears to be a bug in Delphi's JPEG lib. You should report it to QC.
SimDesign's NativeJpg can open that file. It's a JPEG library written entirely in Delphi, and the author has been good about adding support for new extensions and color spaces when we've run into them. In addition to a TGraphic descendant for TImage support it exposes lots of lower-level interfaces for manipulating JPEGs, though I haven't used them.

Resources