2016-12-26 10 views
4

開発中の画像処理アプリケーションで問題が発生しました(ここでは初心者です)。私はgetPixel()メソッドを使用して特定のピクセルの値を抽出しようとしています。getPixel()メソッドを使用して巨大な負の値を抽出しました

私は問題を抱えています。このメソッドから得られる数値は、-1298383のような巨大な負の数です。これは正常ですか?どうすれば修正できますか?

ありがとうございました。

答えて

0

私は専門家ではありませんが、私には16進数の値を得ているようです。多分、あなたはもっと多くのものを望んでいますは各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); 
} 

そして、あなたのことが可能パックピクセル背面各チャンネルの変更後:

はあなたのような何かを行う必要があり、そのRGB値にピクセルを解凍します。

/** 
* 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); 

今、あなたが各チャンネルを取得することができます:

指定された場所に色を返す getPixel()
int redValue = Color.red(pixel); 
int blueValue = Color.blue(pixel); 
int greenValue = Color.green(pixel); 
0

xまたはyが範囲外(負または> =それぞれ幅または高さ)である場合に例外をスローします。

戻ってきた色は、であり、事前に生成されていない ARGB値です。

関連する問題