ojas
ojas

Reputation: 2210

Detect Color Code of live android camera preview

I would like to detect colorcode of image (live stream image) while camera preview is going on. I want to develop sample android application which works like ColorGrab android application. Please find attached screenshot for the same.

How can I make demo program application which capture and recognize colors simply by pointing the camera and show as hexcode of that color.

Any help would be appreciated. Thanks for your time.

enter image description here

Upvotes: 8

Views: 20857

Answers (3)

raj
raj

Reputation: 29

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

Look at this app url, it should give you some idea. It uses this code:

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

Upvotes: 2

Satyavrat
Satyavrat

Reputation: 469

you should try this where x and y is the pixle position

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

Upvotes: 0

Qadir Hussain
Qadir Hussain

Reputation: 8856

This should be your starting point

Get color from image pixel touched

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;    }     
});

You will get the RGB color code.

Got from How to Get Pixel Colour in Android?

Upvotes: 0

Related Questions