2016-07-11 15 views

答えて

0

過去にこのやり方をしてきたのは、イメージをファイルシステムに書き込んでそれをデコードすることです。確かにそれは少し非効率的ですが、機能的です。

これにはいくつかのステップが必要です。私はあなたがこのdocumentationを読むことをお勧めします。ここでは、画像を撮影してファイルシステムに保存する手順について説明します。の前に、の手順を実行することができます。

BitmapFactory画像をデコードすると、Bitmapのインスタンスが得られます(文書化されたhere)。この例では、getPixel()を使用して(50, 50)にあるピクセルのColorオブジェクトを返します。この例では、画像のパスがmCurrentPhotoPathであると仮定していますが、画像を保存した場所である必要があります。

private Color getColor() { 
    // Get the dimensions of the View 
    int targetW = mImageView.getWidth(); 
    int targetH = mImageView.getHeight(); 

    // Get the dimensions of the bitmap 
    BitmapFactory.Options bmOptions = new BitmapFactory.Options(); 
    bmOptions.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); 
    int photoW = bmOptions.outWidth; 
    int photoH = bmOptions.outHeight; 

    // Determine how much to scale down the image 
    int scaleFactor = Math.min(photoW/targetW, photoH/targetH); 

    // Decode the image file into a Bitmap sized to fill the View 
    bmOptions.inJustDecodeBounds = false; 
    bmOptions.inSampleSize = scaleFactor; 
    bmOptions.inPurgeable = true; 
    Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); 
    return bitmap.getPixel(50, 50); 
} 

あなたは、私はあなたがやりたいと思っていると思うものです。このColorオブジェクトからRGB値を取得することができます。これはAndroid開発者のColorオブジェクトドキュメントにも記載されています。