问题描述
当我从图库中将图像加载到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 (将#修改为@)