android获取图字节,Android从byte []数据中提取EXIF元数据

博主有一个自定义相机应用程序,需获取捕获图像的元数据。先保存字节数据,解码后转为常量类,使用前再转为字符串。但使用ExifInterface执行并显示日志时应用崩溃,还给出了相关代码,希望得到帮助。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我有一个自定义相机应用程序.我需要自定义相机捕获的图像的元数据.我先保存了字节数据,然后再解码字节数组(Constant.imageData1 = data;),然后将其保存为类型为byte的常量类,并在使用此字节数据之前将其转换为字符串.当我要使用ExifInterface执行它并显示给日志时,应用程序崩溃.

这是我的OnPictureTaken方法:

PictureCallback mPicture = new PictureCallback() {

@Override

public void onPictureTaken(byte[] data, Camera camera) {

Constant.imageData1 = data;

Log.e("Camrera", "22222222222222222");

BitmapFactory.Options bfo = new BitmapFactory.Options();

bfo.inDither = false;

// bfo.inJustDecodeBounds = true;

bfo.inPurgeable = true;

bfo.inTempStorage = new byte[16 * 1024];

Intent intent = new Intent(context, PreviewActivity.class);

// intent.putExtra("data", data);

Bitmap bitmapPicture = BitmapFactory.decodeByteArray(data, 0,

data.length, bfo);

Matrix matrix = new Matrix();

if (Constant.result == 180) {

matrix.postRotate(270);

}

if (Constant.result == 270) {

matrix.postRotate(180);

}

int height = bitmapPicture.getHeight();

int width = bitmapPicture.getWidth();

//Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmapPicture,

//height, width, true);

Bitmap rotatedBitmap = Bitmap.createBitmap(bitmapPicture, 0, 0,

bitmapPicture.getWidth(), bitmapPicture.getHeight(), matrix,

true);

ByteArrayOutputStream blob = new ByteArrayOutputStream();

Log.e("Camrera1", "22222222222222222");

rotatedBitmap.compress(CompressFormat.JPEG,

50 /* ignored for PNG */, blob);

byte[] bitmapdata = blob.toByteArray();

Constant.imageData = bitmapdata;

Log.e("Camrera2", "22222222222222222");

startActivity(intent);

}

};

这是我的执行代码:

private void SaveImage() {

try {

String data = byteArrayToString(Constant.imageData1);

ExifInterface ex = new ExifInterface(data);

String make = ex.getAttribute(ExifInterface.TAG_MAKE);

Log.e("Make", make);

Log.e("Make", make);

Log.e("Make", make);

finish();

} catch (Exception e) {

e.printStackTrace();

}

}

而bytearraytostring方法是:

public static String byteArrayToString(byte[] bytes)

{

return new String(bytes);

}

这对我来说非常重要.请帮我.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值