i want to create a CloseableReference when i implement a PlatformBitmapFactory the method .of have two implements, if i use the first one
private PlatformBitmapFactory bmpFactory = new PlatformBitmapFactory() {
@Override
public CloseableReference<Bitmap> createBitmap(int width, int height, Bitmap.Config bitmapConfig) {
CloseableReference<Bitmap> cr = CloseableReference
.of(Bitmap.createBitmap(width, height, bitmapConfig));
return cr;
}
};
it would be a compile error: of(java.io.CloseableReference & android.graphics.Bitmap) in CloseableReference cannot be applied to (android.graphics.Bitmap)
But if i use the second one, i dont know how to make a ResourceReleaser .(actually its a interface , a super class of CloseableReference)
how should i put parameter in .of method?
edit:
What I want to achieve is create a reference of Bitmap but do not consume my app's memory(just like DraweeView do). And I have two demands:
One is : get a reference of some new bitmap, same as Bitmap.createBitmap()
, I would save their reference in a List, and then take the reference, further get them, additional draw some thing on them.(more than once)
Two is : get a reference of a drawable and it should be a bitmap, same as BitmapFactory.decodeXXX()
. I would save its reference in a global variable, and then take the reference, further get it, use it Canvas canvas = new Canvas(Bitmap);(more than once too)
Now I try to do like one of implements of PlatformBitmapFactory ArtBitmapFactory
int sizeInBytes = BitmapUtil.getSizeInByteForBitmap(width, height, bitmapConfig);
Bitmap bitmap = mBitmapPool.get(sizeInBytes);
Bitmaps.reconfigureBitmap(bitmap, width, height, bitmapConfig);
return CloseableReference.of(bitmap, mBitmapPool);
but memory increased.