当X、Y位于屏幕中心上方时,java无法获得正确的颜色值
无论何时将值传递到位于屏幕中心或低于屏幕中心的x,y,我都会得到正确的像素颜色,但当传递到屏幕中心以上的x,y的值时,我会得到错误的颜色值,下面是我使用的代码
private int getColor(int x, int y){
Drawable imgDrawable = ((ImageView) mImageView_picture).getDrawable();
Bitmap bitmap1 = ((BitmapDrawable) imgDrawable).getBitmap();
Matrix inverse = new Matrix();
((ImageView) mImageView_picture).getImageMatrix().invert(inverse);
float[] touchPoint = new float[]{x, y};
inverse.mapPoints(touchPoint);
int xCoord = (int) touchPoint[0];
int yCoord = (int) touchPoint[1];
int touchedRGB = bitmap1.getPixel(xCoord,yCoord);
int redValue = Color.red(touchedRGB);
int greenValue = Color.green(touchedRGB);
int blueValue = Color.blue(touchedRGB);
int alphaValue = Color.alpha(touchedRGB);
int colorValue = Color.argb(alphaValue, redValue, greenValue, blueValue);
return colorValue;
}
共 (0) 个答案