我无法从android studio中的imageView获取高度和宽度

问题描述

当我从图库中将图像加载到imageview时,它无法识别图像的高度和宽度,但是我从drawable加载图像,它可以识别图像的高度和宽度。请告诉我我在哪里弄错了?

在这里我附上以下代码,

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);
            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,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,B));
        }
    }
    return bmOut;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...