【发布时间】:2015-08-11 08:24:18
【问题描述】:
我想在进行相机预览时检测图像(实时流图像)的颜色代码。我想开发像ColorGrab android 应用程序一样工作的示例android 应用程序。请在附件中找到相同的屏幕截图。
如何制作演示程序应用程序,只需将相机指向并显示为该颜色的十六进制代码即可捕获和识别颜色。
任何帮助将不胜感激。谢谢你的时间。
【问题讨论】:
标签: android colors android-camera color-picker
我想在进行相机预览时检测图像(实时流图像)的颜色代码。我想开发像ColorGrab android 应用程序一样工作的示例android 应用程序。请在附件中找到相同的屏幕截图。
如何制作演示程序应用程序,只需将相机指向并显示为该颜色的十六进制代码即可捕获和识别颜色。
任何帮助将不胜感激。谢谢你的时间。
【问题讨论】:
标签: android colors android-camera color-picker
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);
【讨论】:
v4.2.2 API 级别:15?或者适用于 Lollipop+ 版本?
这应该是你的起点
从触摸的图像像素中获取颜色
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 颜色代码。
【讨论】:
你应该试试这个,其中 x 和 y 是像素位置
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);
【讨论】: