【发布时间】:2011-11-24 16:17:38
【问题描述】:
我正在尝试从 sdcard 旋转图像,然后保存回 sdcard。
我可以使用 ExifInterface 类为“.jpg”格式做到这一点:
exif = new ExifInterface(filepath);
exif.setAttribute(ExifInterface.TAG_ORIENTATION, Integer.toString(orientation));
exif.saveAttributes();
对于“.png”文件,我必须实际旋转并保存:
Bitmap bitmap = BitmapFactory.decodeFile(filepath);
Matrix matrix = new Matrix();
matrix.postRotate(degrees);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
FileOutputStream stream = new FileOutputStream(fileLocation);
bitmap.compress(CompressFormat.PNG, 100, stream);
“.bmp”、“.tiff”、“.gif”呢??
好像 CompressFormat 只支持 'CompressFormat.PNG' 和 'CompressFormat.JPG'。
这是限制吗?
【问题讨论】:
标签: android image save rotation bmp