AndroidPhotoFilters icon indicating copy to clipboard operation
AndroidPhotoFilters copied to clipboard

New idea for AndroidPhotoFilters

Open hoanganhtuan95ptit opened this issue 5 years ago • 1 comments

Thank you for writing this library. It helped me a lot during the project development process. When integrating into my project I made changes in your library to improve performance. I hope this will help you and the community:

1. Combined with Glide:

Yes, I have integrated the library into the Transformation of glide. With the cache mechanism and excellent flow management of glide, it helps me optimize every time I want to filter and release bitmaps when I no longer use them.

    @Override
    protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
        Bitmap bitmap = TransformationUtils.fitCenter(pool, toTransform, outWidth, outHeight);
        return filter.processFilter(bitmap);
    }

Source: FilterTransformation

2. Release bitmap:

When using the library, I encountered a lot of Out of memory errors. I tried to find a way and there were some solutions:

a) Create copy bitmap:

    public static Bitmap doSaturation(Bitmap inputImage, float level) {
        int width = inputImage.getWidth();
        int height = inputImage.getHeight();
        int[] pixels = new int[width * height];

        inputImage.getPixels(pixels, 0, width, 0, 0, width, height);
        NativeImageProcessor.doSaturation(pixels, level, width, height);

        Bitmap outputImage = inputImage.copy(inputImage.getConfig(), true);
        outputImage.setPixels(pixels, 0, width, 0, 0, width, height);
        return outputImage;
    }

Source: ImageProcessor

b) Recycle bitmap:

    public Bitmap processFilter(Bitmap inputImage) {
        Bitmap outputImage = inputImage;
        for (int i = 0; i < subFilters.size(); i++) {
            SubFilter subFilter = subFilters.get(i);
            Bitmap bitmap = outputImage;
            outputImage = subFilter.process(outputImage);
            if (i != 0 && bitmap != outputImage) {
                bitmap.recycle();
            }
        }
        return outputImage;
    }

Source: Filter

This is the result:

Alt Text

Project:

AndroidFilters

Thank you for reading my post, thank you

hoanganhtuan95ptit avatar May 04 '19 09:05 hoanganhtuan95ptit

Thanks

FaranTariq244 avatar Sep 06 '19 05:09 FaranTariq244