[英]when I convert my rgb bitmap to yuv it results in a red image. I want to read image from gallery in YUV format or convert the RGB bitmap to YUV
I want to use the Y, U and V channel of the image. 我想使用图像的Y,U和V通道。 How can I target those channels? 如何定位这些渠道? need help for the conversion. 需要帮助进行转换。 please give me some example code. 请给我一些示例代码。 Here is my code. 这是我的代码。
public void YUVImage(View view) {
Bitmap bitmap = ((BitmapDrawable)OrignalImg.getDrawable()).getBitmap();//reading image from imageView
int bwidth = bitmap.getWidth();
int bheight = bitmap.getHeight();
Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas c = new Canvas(mutableBitmap);
Toast.makeText(this, "Done 1 ok ",
Toast.LENGTH_LONG).show();
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
Toast.makeText(this, "Done 2 ok ",
Toast.LENGTH_LONG).show();
ColorMatrix yuvMatrix = new ColorMatrix();
yuvMatrix.setRGB2YUV();
Toast.makeText(this, "Now Yuv ok ",
Toast.LENGTH_LONG).show();
ColorFilter filter = new ColorMatrixColorFilter(yuvMatrix);
paint.setColorFilter(filter);
Matrix matrix = new Matrix();
matrix.setTranslate(2*bwidth, 2*bheight);
c.drawBitmap(mutableBitmap, 0, 0, paint);
Toast.makeText(this, "Canvas ok ",
Toast.LENGTH_LONG).show();
ImageView mImg=null;
mImg = (ImageView) findViewById(R.id.imageView1);
mImg.setImageDrawable(new BitmapDrawable(getResources(), mutableBitmap));
//mImg.setImageBitmap(newBitmap);
Toast.makeText(this, "YUV Image converted",
Toast.LENGTH_LONG).show();
}
If you just want the values then simple math is all you need. 如果只需要这些值,那么您只需要简单的数学运算即可。
void rgb2yuv(int r, int g, int b) {
int y = (int)(0.299 * r + 0.587 * g + 0.114 * b);
int u = (int)((b - y) * 0.492f);
int v = (int)((r - y) * 0.877f);
}
just replace 0's with your image size. 只需将0替换为您的图片尺寸即可。
c.drawBitmap(mutableBitmap, x, y, paint); c.drawBitmap(mutableBitmap,x,y,paint);
It helped me. 它帮助了我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.