gpt4 book ai didi

android - onPictureTaken 后旋转 JPEG 的字节数组

转载 作者:可可西里 更新时间:2023-11-01 19:07:18 30 4
gpt4 key购买 nike

有没有办法在不将字节数组解码为位图的情况下旋转字节数组?

目前在 jpeg PictureCallback 中,我只是将字节数组直接写入文件。但是图片是旋转的。我想在不解码为位图的情况下旋转它们,希望这样可以节省我的内存。

    BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data, 0, data.length, o);

int orientation;
if (o.outHeight < o.outWidth) {
orientation = 90;
} else {
orientation = 0;
}

File photo = new File(tmp, "demo.jpeg");

FileOutputStream fos;
BufferedOutputStream bos = null;
try {
fos = new FileOutputStream(photo);
bos = new BufferedOutputStream(fos);
bos.write(data);
bos.flush();
} catch (IOException e) {
Log.e(TAG, "Failed to save photo", e);
} finally {
IOUtils.closeQuietly(bos);
}

最佳答案

试试这个。就解决了这个问题。

Bitmap storedBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, null);

Matrix mat = new Matrix();
mat.postRotate("angle"); // angle is the desired angle you wish to rotate
storedBitmap = Bitmap.createBitmap(storedBitmap, 0, 0, storedBitmap.getWidth(), storedBitmap.getHeight(), mat, true);

关于android - onPictureTaken 后旋转 JPEG 的字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16651831/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com