2015-05-28 61 views
4

我想在攝像頭預覽開始時檢測圖像的顏色代碼(實時流圖像)。我想開發樣例Android應用程序,它的作用類似於ColorGrab android應用程序。請查找相同的截圖。檢測實時安卓攝像頭預覽的顏色代碼

我該如何製作簡單地通過指向相機捕捉和識別顏色並顯示爲該顏色的十六進制代碼的演示程序應用程序。

任何幫助,將不勝感激。謝謝你的時間。

enter image description here

回答

0

這應該是你的起點從圖像像素

獲得色彩感動

targetImage.setOnTouchListener(new ImageView.OnTouchListener(){  
@Override 
public boolean onTouch(View v, MotionEvent event) { 
    // TODO Auto-generated method stub  
    int x=0; 
    int y=0; 
    textView.setText("Touch coordinates : " +  
    String.valueOf(event.getX()) + "x" + String.valueOf(event.getY())); 
    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); 


    return true; }  
}); 

您將得到RGB顏色代碼。

接到How to Get Pixel Colour in Android?

0

你應該試試這其中x和y是在這個程序URL pixle位置

int frameHeight = camera.getParameters().getPreviewSize().height; 
    int frameWidth = camera.getParameters().getPreviewSize().width; 
    int rgb[] = new int[frameWidth * frameHeight]; 
    decodeYUV420SP(rgb, data, frameWidth, frameHeight); 
    Bitmap bmp = Bitmap.createBitmap(rgb, frameWidth, frameHeight, Config.ARGB_8888); 
    int pixel = bmp.getPixel(x,y); 
    int redValue = Color.red(pixel); 
    int blueValue = Color.blue(pixel); 
    int greenValue = Color.green(pixel); 
    int thiscolor = Color.rgb(redValue, greenValue, blueValue); 
+0

你在哪裏設置或獲取在 '數據' 價值 'decodeYUV420SP(RGB,數據,frameWidth,frameHeight);'? –

1

https://play.google.com/store/apps/details?id=com.raj.colorwalls

看,它應該給你一些想法。它使用此代碼:

int frameHeight1 = camera.getParameters().getPreviewSize().height; 
    int frameWidth1 = camera.getParameters().getPreviewSize().width; 
    int rgb1[] = new int[frameWidth * frameHeight]; 
    decodeYUV420SP(rgb1, data, frameWidth, frameHeight); 
    Bitmap bmp1 = Bitmap.createBitmap(rgb, frameWidth1, frameHeight1, Config.ARGB_8888); 
    int pixel = bmp1.getPixel(x,y); 
    int redValue1 = Color.red(pixel); 
    int blueValue1 = Color.blue(pixel); 
    int greenValue1 = Color.green(pixel); 
    int thiscolor1 = Color.rgb(redValue1, greenValue1, blueValue1); 

enter image description here