Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Use BinaryDrawable to Bundle Images into Android JAR Files

DZone's Guide to

Use BinaryDrawable to Bundle Images into Android JAR Files

· Java Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

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.

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}