How to apply different image effects (filters) on bitmap like sepia, black and white, blur, etc.?

旧时模样 提交于 2019-11-28 04:47:15

I have implemented Jerry's Java Image Processing Library. Works fine for me.

Download AndroidJars.

Edit

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
//Find the bitmap's width height
int width = AndroidUtils.getBitmapOfWidth(getResources(), R.drawable.ic_launcher);
int height = AndroidUtils.getBitmapOfHeight(getResources(), R.drawable.ic_launcher);
//Create a filter object.
GaussianFilter filter = new GaussianFilter();
//set???? function to specify the various settings.
filter.setRadius(8.5f);
//Change int Array into a bitmap
int[] src = AndroidUtils.bitmapToIntArray(bitmap);
//Applies a filter.
filter.filter(src, width, height);
//Change the Bitmap int Array (Supports only ARGB_8888)
Bitmap dstBitmap = Bitmap.createBitmap(src, width, height, Config.ARGB_8888);

Find more detailed information at Android-jhlabs

You can use Catalano Framework:

http://code.google.com/p/catalano-framework/

FastBitmap image = new FastBitmap(bitmap);
image.toRGB();

//Sepia
Sepia sepia = new Sepia();
sepia.applyInPlace(image);

//Blur
Blur blur = new Blur();
blur.applyInPlace(image);

//Emboss
Emboss emboss = new Emboss();
emboss.applyInPlace(image);

//Retrieve bitmap
bitmap = fb.toBitmap();

You can also try this project it handle a number of Bitmap Processing

Filters :-

  • Boost-Up Colors
  • Brightness
  • Color Depth
  • Color Filter
  • Contrast
  • Emboss
  • Flip and Rotation
  • Gamma
  • Gaussian Blur
  • Grayscale
  • Hue
  • Invert
  • Noise
  • Saturation
  • Sepia
  • Sharpen
  • Sketch
  • Tint
  • Vignette

Since it is in Java and does pixel label processing, it is not as fast as most C++ based library out there but it work great if bitmap size is not very big eg thumbnails.

This is an excellent Library, easy to integrate with gradle, It is Fast and efficent and saved my day:

https://github.com/wasabeef/picasso-transformations

this is an example of how it's use:

 Transformation trans1 = new ContrastFilterTransformation(getActivity(), 1.5f);
                        Transformation trans2 = new BrightnessFilterTransformation(getActivity(), 0.2f);
                        Picasso.with(getActivity()).load(uri)
                                .transform(trans1).transform(trans2).into(imageview3);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!