8

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

ojas
  • 2,150
  • 5
  • 22
  • 37

3 Answers3

1

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

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
raj
  • 19
  • 3
  • Does this code works on Android `v4.2.2` API Level: `15`? Or works on Lollipop+ versions? – fWd82 Jun 19 '18 at 07:59
  • 1
    Yes it works on Android L and Android M also. You can test it in other versions by installing App : https://play.google.com/store/apps/details?id=com.raj.colorwalls – raj Jun 19 '19 at 13:12
0

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?

Community
  • 1
  • 1
Qadir Hussain
  • 8,721
  • 13
  • 89
  • 124
0

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);
Satyavrat
  • 469
  • 1
  • 7
  • 24