5

When trying to add image files to Images.xcassets, there are certain images that I cannot add. I've tried both dragging-and-dropping as well as using "+" followed by "Import". In the drag-and-drop case, nothing happens. In the Import case, the files I'd like to import are grayed out and cannot be selected.

I'm using Xcode 5.0.2 and I'm trying to import a JPG that's 60x105 pixels, with no transparency or layers.

However, some image files I can import. It's just that the ones I want I cannot for some reason. Are there limitations to the types of images you can import? I've done some googling, searching on forums, and in online developer help for more information about that but haven't found any explanation of any specific limitations on what you can import. Suppose then that no limitations exist, then is there another possible reason why can't I import some of these files?

As an added mystery, the images I'm trying to add are images I've downloaded to do the homework for Stanford's CS 193p course on iPhone programming available on iTunes. I watched the professor of the course drag-and-drop these very files into his Images.xcassets with no problem. So why can't I do that? It seems like I must be missing something obvious!

I'm very stuck on this and I would appreciate any suggestions!

Thanks, Mark Xcode 5, OS X Mavericks (10.9.1)

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3230300
  • 53
  • 1
  • 1
  • 3

2 Answers2

18

I've only ever had luck using PNG images inside the asset catalog. You can use the Preview to open your JPEG image and Export it to PNG.

andrewcbancroft
  • 941
  • 1
  • 9
  • 11
  • 1
    You're right, changing from JPG to PNG works, thank you!! I'm surprised I've never seen the documentation say anywhere that PNG's are accepted but JPG's aren't (maybe I missed it, seems like an important factoid). Thanks for the tip! – user3230300 Jan 24 '14 at 04:51
  • The closest thing I've seen in the documentation that slightly hints at needing a PNG file is [here under the section "Create and Set iOS Launch Images".](https://developer.apple.com/library/ios/documentation/ToolsLanguages/Conceptual/Xcode_Overview/AddIcons,Images,andEffects/AddIcons,Images,andEffects.html#//apple_ref/doc/uid/TP40010215-CH19-SW3) They say "You can use the iPhoto app, for example, to import the screenshot from the device and then export the screenshot to your Mac as a PNG file." – andrewcbancroft Jan 24 '14 at 12:53
  • Also, just ran into this problem and the png extension has to be lowercase (in other words .png, not .PNG). – mohlman3 Apr 15 '14 at 04:25
3

I had a similar issue when trying to add a PNG file as well. I tried Importing as well as drag & dropping, and it simply wouldn't work (wouldn't give me an error, either). For some reason, I had to ensure that the filename ended in lowercase ".png" as opposed to ".PNG".

Not sure why it happened, but simply renaming the extension to lowercase ".png" seemed to fix the problem.