There is a code that receives a photo from the camera:

public byte[] i3; ... Camera i1 = Camera.open(CameraInfo.CAMERA_FACING_BACK); Parameters i2 = i1.getParameters(); i2.setPictureSize(...); i1.setParameters(i2); i1.setPreviewTexture(new SurfaceTexture(0)); i1.startPreview(); i1.takePicture(null, null, new PictureCallback() { @Override public void onPictureTaken(byte[] i1, Camera i2) { i3 = i1.clone(); i2.release(); } }); 

And there is a code that draws an inscription on it:

 Bitmap i5 = BitmapFactory.decodeByteArray(i3.toByteArray(), 0, i3.toByteArray().length).copy(Config.ARGB_8888, true); Canvas i6 = new Canvas(i5); ... 

On the emulator, everything works fine, as on my new Android 4.2.2 phone, but not on the old Android 4.0 phone. There just crashes

In the app ... an error occurred

and nothing else happens. I have completely transferred all my code, Activity whole Activity to a try {} catch (Exception e1) {} - it is useless. Then I connected the phone to a computer and saw via USB debugging in the logs that this line crashes:

 Bitmap i5 = BitmapFactory.decodeByteArray(i3.toByteArray(), 0, i3.toByteArray().length).copy(Config.ARGB_8888, true); 

However, I made sure several times that I also returned it to try {} catch (Exception e1) {} . Unfortunately, in the logs it was not written what kind of exception was thrown, a line was just written, something of the following type:

 in my.package.MyActivity.Thread.run() on line 67... 

in red. Subsequently, I found out that the problem is in the copy(...) method. If I removed it, another error took off telling that it was impossible to draw on Canvas , whose Bitmap is not mutable . How to be? Help correct the error. On the Internet, I did not find a similar problem.


Note. From the first time the picture is perfect and no errors occur. As soon as I try to draw something again in the second new photo, the application crashes. Maybe there is a problem in the lack of memory?

  • with what error crashes, where is the error of the error? - Vladyslav Matviienko
  • @metalurgus, there is no stacktrac in that and strange. If he was, I would understand at least some error flies. - nick
  • I still think there is a Stacktreys, but you just don’t notice it. - Vladyslav Matviienko
  • @metalurgus, it is not. Only one line. Wait 3 minutes, I still run again. - nick
  • @metalurgus, 10-10 22:45:05.239: I/dalvikvm(19087): at my.package.MyActivity$1$1.run(MyActivity.java:140) . Line 140 says Bitmap i5 = BitmapFactory.decodeByteArray(i3.toByteArray(), 0, i3.toByteArray().length).copy(Config.ARGB_8888, true); . More from this application is not written anything. There are only a few lines in which Activity read to stop... stopping... exit pid... , that is, a log from the system itself. I am 100% sure that in these logs there is no important information. - nick

2 answers 2

To make a mutable image:

 bm = bm.copy(Config.ARGB_8888, true); 

But it is easier to draw a text or a picture instead of your example.

 canvas.drawText canvas.drawBitmap 
  • This code does not work. I wrote in the question. He flies. This is the problem. I just cut the code a little bit. Find the line "And there is a code that draws an inscription on it:" in my question and below you will see the code. - nick
  • Not that. Not null returned, but an IOException, or even an IOError. I can not even say, because it is not written in the logs. - nick
  • one
    And build the application (without too much) and put it somewhere, it is interesting to see how it crashes. Silently, an application crashes only when the system dies completely, and then it is no longer up to your application, or when the exit from it is deliberately caused somewhere, in all other cases there are thick-thick logs in the logs. You can also hang up the handler for all thread errors through setDefaultUncaughtExceptionHandler () and catch the moment from a separate class, immediately writing the result to a file (access to the windows may not be available at that moment). - bukkojot

Once I came across an OutOfMemoryException that crashed an application and was hard to catch. The bottom line is that the Bitmap may be too large to render on canvas, so you can try to reduce it by 2 or 4 times, that is, fit the screen size.

  • Unfortunately, this does not solve my problem. I have to do without reducing the size. - nick