android一个像素多少字节,Android中某些相机分辨率的不同捕获输出大小

我正在使用

Android Camera2 API开发自定义相机应用程序,您可以在手机中提供不同的相机和视频分辨率.它还提供了拍摄平方1:1照片的可能性.为了拍摄正方形照片,我拍摄正常的4:3照片,然后裁剪它以保持1:1. (所以4032×3024将是3024×3024).

我注意到在某些分辨率上拍摄1:1照片时出现问题,输出会略微裁剪(缩放).这是使用两种不同分辨率拍摄的相同照片的结果:

我的Nexus 5X在4:3上支持12MP,8MP,5MP和2MP.当我使用任何大于500万像素的分辨率时会发生此问题.

我用来裁剪图像的方法如下:

ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();

byte[] bytes = new byte[buffer.remaining()];

buffer.get(bytes);

cropSquareImageByteArray(bytes);

cropSquareImageByteArray方法:

public static byte[] cropSquareImageByteArray(byte[] bytes) {

ByteArrayOutputStream bos = new ByteArrayOutputStream();

Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

int w = bitmap.getWidth();

int h = bitmap.getHeight();

Bitmap dst = Bitmap.createBitmap(bitmap, 0, h - w, w, w);

dst.compress(Bitmap.CompressFormat.JPEG, 98, bos);

return bos.toByteArray();

}

我猜测裁剪的原因是16:9容器中的4:3图像.因为我在打电话时注意到了

Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

生成的位图输出的尺寸在2MP时为1280×960(4:3),在500万像素时为1600×1200(4:3),但对于更大的分辨率为1920×1080(16:9),因此4:3图像调整为16:9位图,可能导致裁剪.

*编辑:我的ImageReader配置如下:

public void configureImageReader(Size pictureSizeValue, ImageReader.OnImageAvailableListener listener) {

if (mImageReader == null) {

mImageReader = ImageReader.newInstance(pictureSizeValue.getWidth(), pictureSizeValue.getHeight(),

ImageFormat.JPEG, 2);

}

mImageReader.setOnImageAvailableListener(listener, mBackgroundHandler);

}

pictureSizeValue的值是我想要的输出.所以对于平方图像,它就像3024×3024.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值