Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did find an answer to this question after looking at the native android code that backs the Bitmap. Android only can only save certain types of bitmaps to the picture. This is because the SkBitmap class only supports certain types of inputs that result in a bitmap that can be saved to a Picture. So in this can I can workaround the problem by providing those magical inputs. Use a bitmap that is saved to disk and call BitmapFactory.decodeFileDescriptor to create it.</p> <pre><code>private Bitmap createReusableBitmap(Bitmap inBitmap) { Bitmap reuseableBitmap = null; if (inBitmap== null) return null; try { // The caller is responsible for deleting the file. File tmpBitmapFile = File.createTempFile("bitmap", ".png"); setBitmapPath(tmpBitmapFile.getAbsolutePath()); FileOutputStream out = new FileOutputStream(tmpBitmapFile); boolean compressed = inBitmap.compress(CompressFormat.PNG, 100, out); out.close(); if (compressed) { // Have to create a purgeable bitmap b/c that is the only kind that works right when drawing into a // Picture. After digging through the android source I found decodeFileDescriptor will create the one we need. // See https://github.com/android/platform_frameworks_base/blob/master/core/jni/android/graphics/BitmapFactory.cpp // In short we have to give the options inPurgeable=true inInputShareable=true and call decodeFileDescriptor BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inInputShareable = true; options.inPurgeable = true; options.inSampleSize = 1; options.inScaled = false; options.inMutable = false; options.inTempStorage = DraftRenderer.tempStorage; FileInputStream inStream = new FileInputStream(tmpBitmapFile); FileDescriptor fd = inStream.getFD(); reuseableBitmap = BitmapFactory.decodeFileDescriptor(fd, null, options); inStream.close(); } } catch (Exception e) { } return reuseableBitmap; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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