Why do Postprocessors modify the source Bitmap?
Hi! I was wondering why you designed the Postprocessors to modify the source Bitmap, instead of returning a new one like Picasso/Glide's Transformations. I find that often it's very hard to modify a bitmap in place, so you end up having to create a new result Bitmap, and then copying all its pixels over to the source one, which seems less efficient. Thanks!
Because, on Android 4.x, the bitmaps are purgeable - the big pixel data lives in the ashmem heap, not the Java heap. If you use the Bitmap.copy operation this will put all the pixels on the Java heap, the very thing Fresco is designed to avoid.
Internally, Fresco copies the Bitmap for you, so that any changes you make to it don't affect the version in cache. Moreover, Fresco's copy is done safely, keeping the pixel data in ashmem.
Can you tell us what operation you are doing that is hard to do in-place?
I'm doing some kind of "stack" effect on that bitmap, where the source image is blurred, scaled down a little, and painted again in the output multiple times, if that makes sense. Maybe I'm missing a better way to do this, but because I need to access the source bitmap to paint each "layer", I don't think I can just modify that source bitmap. This processing takes in average ~50ms, is there maybe a way I can change the ImageRequest to cache that postprocessed image in the memory cache instead of the source one?
I'm doing something similar. A solution to this would be awesome!
Hi, we are aware of this and I already proposed that we change that. This should be easy to solve though. We should just pass both source and destination bitmap. And one should not modify the source bitmap. One limitation of that is that the output bitmap would have to be of the same size, but we can change even that by allowing clients to create their own output bitmap. Let me make a solution for that.
Caching is as separate issue, and we will consider implementing that as well.
I have a fix ready for this.
Can I get a sample code on how to use Postprocessors in fresco. Any help will be appreciated.
amitshekhariitbhu: see http://frescolib.org/docs/modifying-image.html
I refactored postprocessors so that the client has more flexibility. This is soon going to be pushed to maven, and if you are building from source you should extend BasePostprocessor:
https://github.com/facebook/fresco/blob/29080993fce3ccfcdc83a03f1d0a533ee18f72aa/imagepipeline/src/main/java/com/facebook/imagepipeline/request/BasePostprocessor.java
This is included in Fresco 0.3.0 which has just been released. See the updated documentation.
@tyronen : thanks
@plamenko Hi, Apologies for writing on this closed thread. I want to blur the whole image after fresco load it. Could you give a sample code for this?
Write now I am doing this
Postprocessor blurringPostprocessor = new BasePostprocessor() {
@Override
public String getName() {
return "blurringPostprocessor";
}
@Override
public void process(Bitmap bitmap) {
//using bluring view to blur the image
blurringView.invalidate();
}
};
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(parseProfileObject.getParseFile("profilePic").getUrl()))
.setPostprocessor(blurringPostprocessor)
.setResizeOptions(new ResizeOptions(512, 334))
.build();
PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
.setOldController(backgroundPhoto.getController())
.setImageRequest(request)
.build();
PS: Pardon me for my Language.