Android Best way to convert byte array to Bitmap?

I know why OutOfMemoryError Exception occurs.But there are any best way to convert byte array to Bitmap.And I used below code ,But when large byte it force close app and gives OutOfMemoryError Exception.

And i have API it just return me byte array nothing else.

  • Why Android Gradle preDexDebug “Source and destination must be different” build failed?
  • CPU usage per application in android
  • Android Actionbar change menus position
  • Make navigation drawer draw behind status bar
  • Android: Flash content breaks WebView boundings and overlaps native layout elements
  • Display all Unicode chars in TextView
  • Bitmap bmp = BitmapFactory.decodeByteArray(bytearray, 0, bytearray.length);

    Related posts:

    Is there a way to get references for all currently active fragments in an Activity?
    Android Emulator Tips and Tricks
    Set Progress of Dialog
    How to check if phone is mute, vibrate or loud in android
    TextToSpeech with API 21
    Android AlarmManager problem with setting & resetting an alarm
  • Android EditText delete(backspace) key event
  • Quickest way to duplicate an android project?
  • Android Studio, Gradle, OpenCV and NDK
  • How to display transparent activity on the another activity without removing previous activity
  • Set own layout in popup window in android
  • How to configure dry run and log level options via XML in Google Analytics v4 SDK for Android?
  • 4 Solutions collect form web for “Android Best way to convert byte array to Bitmap?”

    Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapbytes , 0, bitmapbytes .length);

    Returns The decoded bitmap, or null if the image could not be decode.

    Here is what worked for me:
    photo is a string of an image by the way.

    byte[] imgbytes = Base64.decode(photo, Base64.DEFAULT);
    Bitmap bitmap = BitmapFactory.decodeByteArray(imgbytes, 0,

    You probably have to use this following method (DOC, same method, but with the options parameter):

    public static Bitmap decodeByteArray (byte[] data, int offset, int length, BitmapFactory.Options opts)

    And play with the options parameter. Hope this will help you =)

    You may want to use the AQuery library to load your images, this will help you resize, view etc and avoid the most common memory leaks. This tool can be found here:

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.