Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid Picture.createFromStream does not reload bitmaps
    primarykey
    data
    text
    <p>On android I am drawing into a android.graphics.Picture then save the Picture to a file. Later I reload the picture into memory and draw it to the canvas. I noticed that Bitmaps were never drawing. And after much debugging I managed to narrow down the problem to Picture.writeToStream and Picture.createFromStream. It seems that Bitmaps drawn into the picture don't get reloaded properly. Below is sample code I wrote to show the problem. In this sample my canvas is not hardware accelerated.</p> <p>So my questions are as follows:</p> <ol> <li>Am I doing something wrong?</li> <li>Is this an Android bug? I filed the bug report <a href="https://code.google.com/p/android/issues/detail?id=54896" rel="nofollow">https://code.google.com/p/android/issues/detail?id=54896</a> because I think this is.</li> <li><p>Any known workaround?</p> <pre><code>@Override protected void onDraw(Canvas canvas) { try { Picture picture = new Picture(); // Create a bitmap Bitmap bitmap = Bitmap.createBitmap( 100, 100, Config.ARGB_8888); Canvas bitmapCanvas = new Canvas(bitmap); bitmapCanvas.drawARGB(255, 0, 255, 0); // Draw the bitmap to the picture's canvas. Canvas pictureCanvas = picture.beginRecording(canvas.getWidth(), canvas.getHeight()); RectF dstRect = new RectF(0, 0, 200, 200); pictureCanvas.drawBitmap(bitmap, null, dstRect, null); picture.endRecording(); // Save the Picture to a file. File file = File.createTempFile("cache", ".pic"); FileOutputStream os = new FileOutputStream(file); picture.writeToStream(os); os.close(); // Read the picture back in FileInputStream in = new FileInputStream(file); Picture cachedPicture = Picture.createFromStream(in); // Draw the cached picture to the view's canvas. This won't draw the bitmap! canvas.drawPicture(cachedPicture); // Uncomment the following line to see that Drawing the Picture without reloading // it from disk works fine. //canvas.drawPicture(picture); } catch (Exception e) { } } </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload