I was trying to display a picture file using ImageView, although I knew that I could decode the file to bitmap directly, but I have to do some other thing to it, so I could only choose byte[].
The code looks like this:
File file = new File(getRealPathFromURI(Uri.parse(ImgUri)));
byte[] beforeData = new byte[(int) file.length()];
try {
FileInputStream fis = new FileInputStream(file);
int detectEnd = 0;
while (detectEnd != -1){detectEnd = fis.read(beforeData, 0, 1024);}
Bitmap b_t = BitmapFactory.decodeByteArray(beforeData, 0, beforeData.length);
editImgView.setImageBitmap(b_t);
} catch (FileNotFoundException e) {e.printStackTrace();}
catch (IOException e) {e.printStackTrace();}
I tried to test out if I read in the picture correctly, so I decode in to Bitmap then try to display it, but it does not display any picture at all.
Is there anything that I misunderstood with FileInputStream? PS. I use log.i to check and found that beforeData's length is normal, but the data inside only get: [B@40c4b110 , which is not like a picture's data.
Thanks in Advance, Desolve.
Oops, thanks you siliconeagle, I forgot to consider that part...(At the very beginning I did) However, it seems like it's not where the main problem is... Now the loop looks like:
while (pos < beforeData.length){
read = fis.read(beforeData, pos, 1);
pos += read;
}
It's stupid and dummy I know, but the code in this block should work properly, right? However, I still couldn't see any picture in my ImageView.
Another PS: The file's path is at /mnt/sdcard/DCIM/Camera/1310368442822.jpg, size 1485847 bytes, would size cause any trouble?