Mar*_*kus 14 android android-camera
有没有办法旋转字节数组而不将其解码为Bitmap?
目前在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);
}
Run Code Online (Sandbox Code Playgroud)
尝试这个。它将解决目的。
Run Code Online (Sandbox Code Playgroud)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);
| 归档时间: |
|
| 查看次数: |
12491 次 |
| 最近记录: |