0

I use the following code to square a bitmap that is rectangular :

private static Bitmap squareBitMap(Bitmap givenBitmap) {
        int dim = Math.max(givenBitmap.getWidth(), givenBitmap.getHeight());
        Bitmap resultBitmap= Bitmap.createBitmap(dim, dim, Config.ARGB_8888);

        Canvas canvas = new Canvas(resultBitmap);
        canvas.drawColor(Color.WHITE);


        canvas.drawBitmap(givenBitmap, (dim - givenBitmap.getWidth()) / 2, (dim - givenBitmap.getHeight()) / 2, null);

        return resultBitmap;
    }

And this code to blur a bitmap.

There are many apps in google play that blur and square bitmap like that:

EXAMPLE

enter image description here

how can i achieve that?

Community
  • 1
  • 1
Device
  • 983
  • 3
  • 11
  • 26
  • possible duplicate of [Fast Bitmap Blur For Android SDK](http://stackoverflow.com/questions/2067955/fast-bitmap-blur-for-android-sdk) – Viktor Yakunin Aug 03 '15 at 11:35
  • Check http://chiuki.github.io/android-shaders-filters/#/43. I didn't try but it could be a good point to start from ;) – Gordak Aug 03 '15 at 11:36

1 Answers1

1

you can use below library to blur image

https://github.com/wasabeef/Blurry

using below code you have to create square bitmap :

if (srcBmp.getWidth() >= srcBmp.getHeight()){

  dstBmp = Bitmap.createBitmap(
     srcBmp, 
     srcBmp.getWidth()/2 - srcBmp.getHeight()/2,
     0,
     srcBmp.getHeight(), 
     srcBmp.getHeight()
     );

}else{

  dstBmp = Bitmap.createBitmap(
     srcBmp,
     0, 
     srcBmp.getHeight()/2 - srcBmp.getWidth()/2,
     srcBmp.getWidth(),
     srcBmp.getWidth() 
     );
}
Darshan Mistry
  • 3,249
  • 1
  • 16
  • 28
  • first, you have to set bitmap in imageview and using this library imageview can be blur.so you have to write a code to create square bitmap – Darshan Mistry Aug 03 '15 at 11:34