0
我想将捕获的图像转换为字节[]。当我使用相机捕获图像时,它会被捕获,预览也会显示,并且图像也会成功保存在我的外部存储上。但是,当我尝试转换预览图像时,它不会在字节数组中存储任何内容。 以下是我在手机上按下预览图像按钮时调用的方法。无法将位图图像转换为字节[]
public static void previewCapturedImage() {
try {
static ByteArrayOutputStream stream = null;
imgPreview.setVisibility(View.VISIBLE);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),options);
imgPreview.setImageBitmap(bitmap);
stream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
} catch (NullPointerException e) {
e.printStackTrace();
}
}