0

when i load image from gallery to the imageview, it can't recognize the height and width of the image, but i load the image from drawable , it recognize the height and width of the image. please tell where i made a mistake?

here i attached the code below,

Blockquote

     source = BitmapFactory.decodeResource(getResources(),R.id.image);

    mRed = findViewById(R.id.red);
    mRed.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            bitmap = applyColorFilterEffect(source, 255, 0, 0);
            imageView.setImageBitmap(bitmap);
        }
    });

Blockquote

 public Bitmap applyColorFilterEffect(Bitmap src, double red, double green, double blue) {
    // image size
    int width = src.getWidth();
    int height = src.getHeight();

  // create output bitmap
    Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
    // color information
    int A, R, G, B;
    int pixel;

    // scan through all pixels
    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
             //get pixel color
            pixel = src.getPixel(x, y);
            // apply filtering on each channel R, G, B
            A = Color.alpha(pixel);
            R = (int) (Color.red(pixel) * red);
            G = (int) (Color.green(pixel) * green);
            B = (int) (Color.blue(pixel) * blue);
            // set new color pixel to output bitmap
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }
    return bmOut;
}
Thivviya
  • 31
  • 3
  • You can ImageIVew.getDrawingCache. refer: https://stackoverflow.com/questions/8880376/how-to-get-the-height-and-width-of-an-imageview-bitmap-in-android#8880528 – Akshay Aug 21 '20 at 08:02
  • you have posted working code with `Bitmap` from drawable... how do you obtain this not-working-gallery-image? – snachmsm Aug 21 '20 at 08:12
  • i tried it also .. after installation when i click the mRed button it comes out of the app. – Thivviya Aug 21 '20 at 08:17

0 Answers0