A Bitmap is a representation of a bitmap image. Android supports bitmap files in three formats .png, .jpg and .gif. Converting drawable image to bitmap is easy in android. This example teaches you to convert a drawable image to bitmap and display it in ImageView with simple java code.

In order to convert drawable image to bitmap in android, you have to use android.graphics.Bitmap and android.graphics.BitmapFactory.

Related:
Capture Image from Android Camera and Display it Programmatically
How to Open a URL in Android Browser from Application
Pick an Image From SD Card Gallery and Display in Android App

Android Example: Convert a Drawable to a Bitmap in Android


Following is the code of java activity file and XML layout file.

XML Layout File


res/layout/convert_drawable_to_bitmap.xml


Java Activity File


src/ ConvertDrawableToBitmap.java


Strings.xml File


res/values/strings.xml

Android Example: Convert a Drawable to a Bitmap in Android

Now, run you Convert Drawable to Bitmap in Android application, you will see ViralAndroid’s logo icon in the screen which is converted drawable to bitmap.

Post a Comment

Powered by Blogger.