android bitmap nv21,android - How to convert NV21 image format in bitmap? - Stack Overflow

I am getting preview data from camera. It is in NV21 format. I want to save the preview to SD Card i.e in bitmap. My code is getting image and saving it, but in the gallery it is not captured preview. It is just black rectangle, Here is the code.

public void processImage() {

Bitmap bitmap = null;

if (flag == true) {

flag = false;

if (mCamera != null) {

Camera.Parameters parameters = mCamera.getParameters();

int imageFormat = parameters.getPreviewFormat();

if (imageFormat == ImageFormat.NV21) {

Toast.makeText(mContext, "Format: NV21", Toast.LENGTH_SHORT)

.show();

int w = parameters.getPreviewSize().width;

int h = parameters.getPreviewSize().height;

YuvImage yuvImage = new YuvImage(mData, imageFormat, w, h,

null);

Rect rect = new Rect(0, 0, w, h);

ByteArrayOutputStream baos = new ByteArrayOutputStream();

yuvImage.compressToJpeg(rect, 100, baos);

byte[] jData = baos.toByteArray();

bitmap = BitmapFactory.decodeByteArray(jData, 0,

jData.length);

}

else if (imageFormat == ImageFormat.JPEG

|| imageFormat == ImageFormat.RGB_565) {

Toast.makeText(mContext, "Format: JPEG||RGB_565",

Toast.LENGTH_SHORT).show();

bitmap = BitmapFactory.decodeByteArray(mData, 0,

mData.length);

}

}

if (bitmap != null) {

saveImage(bitmap);

Toast.makeText(mContext, "Image Saved", Toast.LENGTH_SHORT)

.show();

} else

Toast.makeText(mContext, "Bitmap Null", Toast.LENGTH_SHORT)

.show();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值