I am trying to use a background image... when I place the file.png in the drawable folder, eclipse recognizes it and everything works.
However, file.jpg doesn't work.
Can someone please tell me what I'm doing wrong and how to resolve this?
I know it must work because in the docs it said the drawable resource can be a jpeg file also.
Drawable myImage = ResourcesCompat. getDrawable(res, R. drawable. my_image, null);
Because of their different compression processes, JPEGs contain less data than PNGs — and therefore, are usually smaller in size. Unlike JPEGs, PNGs support transparent backgrounds, making them preferred for graphic design.
You'll generally get better compression with JPEG than with PNG, but if quality is your priority you may want to stick with PNG since it's guaranteed to be lossless.
To import image resources into your project, do the following: Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import.
This is to clarify the issue for the other beginners out there that are running into this. This appears to be a rampant issue that gets most beginners and wastes a ton of time. Just google "eclipse load drawable" and look at all the people having trouble. They all end with "well, it works now but I don't know why...".
I've had the same issue on two different projects over the last couple days. There does appear to be an issue (undocumented feature?) with Eclipse. First, make sure the filename is in all lowercase. This wasn't immediately clear to me until i read [a-z1-9_.] about a hundred times. It does NOT in fact say [a-zA-Z1-9_.].
Second you need to restart Eclipse after adding drawable images to a project. Eclipse will not build the drawable resources during it's normal operation. The example of this is to simply add an image (png or jpg) and manually build the project. No matter how many times you build or clean the project, the images will not show up in /bin/res/drawable. Now save your project and click File->Restart. Auto-magically the images are in the bin folder, can be referenced using @drawable/, and do not cause build errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With