0

I want to get exactly the bitmap shown on screen after scale, filtercolor, ... and work with its pixels, for example in order to remove transparent pixels:

 for (int y = 0; y < sourceBitmap1.getHeight(); y++) 
        for (int x = 0; x < sourceBitmap1.getWidth(); x++) 
            if (sourceBitmap1.getPixel(x, y) == Color.TRANSPARENT) {
                  //todo do something
            }

But it is important to get bitmap related to target Imageview. As I have seen in other posts I can do this with this method:

 public static Bitmap loadBitmapFromView(ImageView i) {
    i.setDrawingCacheEnabled(true);
    i.measure(FrameLayout.MeasureSpec.makeMeasureSpec(0,   FrameLayout.MeasureSpec.UNSPECIFIED),
            FrameLayout.MeasureSpec.makeMeasureSpec(0,    FrameLayout.MeasureSpec.UNSPECIFIED));
    i.layout(0, 0, i.getMeasuredWidth(), i.getMeasuredHeight());
    i.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(i.getDrawingCache(true));
    i.setDrawingCacheEnabled(false);
    return b;
}

But why does the method return null?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
FxRi4
  • 1,096
  • 10
  • 15

1 Answers1

0

try this to get bitmap from imageview

 Bitmap bitmap = ((BitmapDrawable) imgview.getDrawable()).getBitmap();
Manish Menaria
  • 23,899
  • 3
  • 21
  • 23
  • i check this not return scaled bitmap ,this return exacly drawable bitmap consider drawble bitmap is 500*500 but imageview bitmap is 200*200 it return 500*500 drawble – FxRi4 Jun 18 '16 at 10:59