Hi everyone. I'm totally new to android programming and I can't get rid of an error that occurs when running my application in my phone (the error doesn't occur in the emulator).
I'm trying to make a picture with the camera and then convert the byte[] that the onPictureTaken function returns into a bitmap. I tried 2 approaches that both fail. So hopefully one of you sees the problem
Below is the part of my code in which the problem occurs. When i just open and close the inputstream, everything works fine. But when i uncomment one of the two methods to create a bitmap, then the app crashes after taking about 3 pictures (on the fourth it gives the "application stopped unexpectedly" error). It only happens in the real phone, not in the emulator, so i don't have a logcat.
BitmapFactory.decodeStream returns null when bytes is null, or when bytes is not a valid inputstream to create a bitmap from, so i guess that the problem can't be that bytes is null or something like that.
Does anyone see the problem? (if you need more code, let me know)
I'm trying to make a picture with the camera and then convert the byte[] that the onPictureTaken function returns into a bitmap. I tried 2 approaches that both fail. So hopefully one of you sees the problem
Below is the part of my code in which the problem occurs. When i just open and close the inputstream, everything works fine. But when i uncomment one of the two methods to create a bitmap, then the app crashes after taking about 3 pictures (on the fourth it gives the "application stopped unexpectedly" error). It only happens in the real phone, not in the emulator, so i don't have a logcat.
BitmapFactory.decodeStream returns null when bytes is null, or when bytes is not a valid inputstream to create a bitmap from, so i guess that the problem can't be that bytes is null or something like that.
Code:
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] imageData, Camera c) {
System.out.println(imageData);
try{
ByteArrayInputStream bytes = new ByteArrayInputStream(imageData);
// Bitmap bm = BitmapFactory.decodeStream(bytes); #Method 1
// BitmapDrawable bmd = new BitmapDrawable(bytes); #Method 2
bytes.close();
}catch(IOException e) {
e.printStackTrace();
}
}
};