Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New idea for AndroidPhotoFilters #44

Open
hoanganhtuan95ptit opened this issue May 4, 2019 · 1 comment
Open

New idea for AndroidPhotoFilters #44

hoanganhtuan95ptit opened this issue May 4, 2019 · 1 comment

Comments

@hoanganhtuan95ptit
Copy link

hoanganhtuan95ptit commented May 4, 2019

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

@FaranTariq244
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants