Over a million developers have joined DZone.

Use BinaryDrawable to Bundle Images into Android JAR Files

· Java Zone

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

Android developers interested in including images in their JAR files - at least those making limited use of images and hoping to avoid the trouble of a res folder or Android library project - might find BinaryDrawable, a new tool from Hipmob, to be useful. According to Hipmob, it works like this:

To convert any image that can be understood by the Android platform's built-in BitmapFactory into a BinaryDrawable instance we simply read the image file and create a Java source file that includes a byte array with the image data. The generated class can then use decodeByteArray to get a Bitmap, and then it is a short hop to a BitmapDrawable.

Be aware, though, that there are some serious limitations to this tool: only very small images will work (under about 10kb), and JPG and PNG are the only acceptable formats. So, BinaryDrawable isn't for everybody, but if you only need small images here and there - icons seem like the most likely use - it could be worth checking out.

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}