Skip to content Skip to sidebar Skip to footer

Conversion From File To Bitmap In Android

Ok I have updated my question. This is my upload image to server project. Everything works fine no errors, but I keep getting files that are 10, 12 or 16 bytes. But with right name

Solution 1:

use this code

FileimgFile=newFile(selectedImageUrl);
            if(imgFile.exists()){
                BitmapmyBitmap= BitmapFactory.decodeFile(imgFile.getAbsolutePath());
}

Solution 2:

I usually use the helper methods below that works quite well. Give them a try.

publicstatic Bitmap convertBLOB2Bitmap(byte[] blob) {
    Optionsoptions=newBitmapFactory.Options();
    Bitmaptmp= BitmapFactory.decodeByteArray(blob, 0, blob.length, options);
    return tmp;
}


publicstaticbyte[] convertBitmap2BLOB(Bitmap bitmap) {
    ByteArrayOutputStreambos=newByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 0/* ignored for PNG */, bos);
    return bos.toByteArray();
}

Post a Comment for "Conversion From File To Bitmap In Android"