Translate

Friday, June 10, 2016

How to measure colors from your app using ColorMeter

ColorMeter updated (v3.1.0) with new ability to export measurement results. If you have the app installed on a device, you can measure color  from your application by calling ColorMeter. Currently you will get RGB and HEX color result as JSON string (see code example below).



How to call from your application:

Intent intent = new Intent("com.vistechprojects.colormeter.action.MEASURE_COLOR");
intent.setDataAndType(IMAGE_SOURCE_URI, "image/*"); // comment this line if you don't pass image uri
startActivityForResult(intent, REQUEST_CODE); // replace REQUEST_CODE with your constant

Example how to get results:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
...

if (resultCode == RESULT_OK && requestCode == REQUEST_CODE){
     JSONObject json = new JSONObject(data.getStringExtra("CM_OUTPUT_JSON"));
     ...
}
...
}

JSON returned from ColorMeter: 

{"APP_RESULTS":{"RGB":"112,63,30","HEX":"#703F1E"}}

Update v3.1.1:

This update allows you to set default size of averaging window by passing index parameter.

The index must be an integer value from 0 to 10 and it corresponds to default window sizes 1x1, 3x3, ..., 21x21 pixels.

Intent intent = new Intent("com.vistechprojects.colormeter.action.MEASURE_COLOR");
intent.setDataAndType(IMAGE_SOURCE_URI, "image/*"); // comment this line if you don't pass image uri
intent.putExtra("averaging_size_index", INDEX);  // INDEX must be an integer value from 0 to 10
startActivityForResult(intent, REQUEST_CODE); // replace REQUEST_CODE with your constant

Also in the new version it is possible to read each color channel separately:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
...
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE){
     int red = data.getIntExtra("CM_OUTPUT_RED", 0));
     int green = data.getIntExtra("CM_OUTPUT_GREEN", 0);
     int blue = data.getIntExtra("CM_OUTPUT_BLUE", 0);
     String hex = data.getStringExtra("CM_OUTPUT_HEX");
     ...
}
...
}


ColorMeter Android app on Google Play

No comments:

Post a Comment