解码ByteArrray以将位图显示到ImageView Android中

Probably I'm repeating the same question but I haven't found solution to this problem & many of the same questions are still un-answered. So , here is my question :

I have implemented PHP backend where user can upload pictures in any image format & it will be saved as BLOB in MySQl database . To retrieve these images on Android device I have prepared JSON response in which these images are in form of base64 strings.

PHP Code :

$rightScrollImage= base64_encode($row['right_image']);

Now, on the Android side these image will be saved in SQLite database & here is

CODE TO INSERT IMAGE :

rightScrollImage.setRightimagedata(Base64.decode(row.getString("rightScrollerImage"), 0));

WHERE datatype for this field in SQLite also as BLOB.

CODE TO DISPLAY IMAGE :

byte[] imageData = cursor.getBlob(cursor.getColumnIndex(DatabaseManager.RIGHT_IMAGE));

Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
imageStream.reset();
holder.imageView.setImageBitmap(bitmap);

Problem with this code is it can decode few images & those which are not displayed got error of "D/skia: --- decoder->decode returned false" .

Try this:

String rightScrollerImage = urlFromItsComing();
byte[] image= Base64.decode(rightScrollerImage, Base64.DEFAULT);
Bitmap = bmpImage = BitmapFactory.decodeByteArray(image, 0, image.length);
someImageView.setImageBitmap(bmpImage);

Update (if you save string first in db):

SaveInColumnWith_String_Datatype(rightScrollerImage);
String image_data = cursor.getString(cursor.getColumnIndex(DBData.ColumnName));
    byte[] image= Base64.decode(image_data, Base64.DEFAULT);
    Bitmap = bmpImage = BitmapFactory.decodeByteArray(image, 0, image.length);
    someImageView.setImageBitmap(bmpImage);

If you are saving in BLOB Data Type Field, Before Saving, Convert String to byte[], like:

    byte[] image_byte_data = Base64.decode(imageDataString, Base64.DEFAULT);

SaveInColumnWith_BLOB_Datatype(image_byte_data);

byte[] image_data = cursor.getBlob(cursor.getColumnIndex(DBData.ColumnName));
    Bitmap = bmpImage = BitmapFactory.decodeByteArray(image_data, 0, image.length);
    someImageView.setImageBitmap(bmpImage);