Huge negative values ​​obtained using getPixel () method

I am having a problem with an image processing application that I am developing (new to here). I am trying to extract the value of specific pixels using a method getPixel().

I have a problem. The number I get from this method is a huge negative number, something like -1298383. This is normal? How can i fix this?

Thank.

+4
source share
3 answers

I am not an expert, but it seems to me that you are getting a hex value. Perhaps you need something more comprehensible, like the meaning of each RGB layer.

RGB, - :

private short[][] red;
private short[][] green;
private short[][] blue;

 /** 
 * Map each intensity of an RGB colour into its respective colour channel
 */
private void unpackPixel(int pixel, int row, int col) {
    red[row][col] = (short) ((pixel >> 16) & 0xFF);
    green[row][col] = (short) ((pixel >> 8) & 0xFF);
    blue[row][col] = (short) ((pixel >> 0) & 0xFF);
}

.

/** 
 * Create an RGB colour pixel.
 */
private int packPixel(int red, int green, int blue) {
    return (red << 16) | (green << 8) | blue;
}

, , .

0

:

ImageView imageView = ((ImageView)v);
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
int pixel = bitmap.getPixel(x,y);

:

int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
0

getPixel() . , x y ( >= ).

- ARGB.

0

Source: https://habr.com/ru/post/1664919/


All Articles