我想從SD卡旋轉圖像,然後保存回SD卡。Android:我如何保存不是(JPEG&PNG)的圖像文件? [旋轉後]
我能做到這一點通過使用ExifInterface類名爲 「.jpg」 格式:
exif = new ExifInterface(filepath);
exif.setAttribute(ExifInterface.TAG_ORIENTATION, Integer.toString(orientation));
exif.saveAttributes();
對於 「巴紐」 文件,我將不得不實際旋轉並保存:
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'。
這是限制嗎?
文件ex緊張局勢只是一個慣例。它會將PNG圖像保存爲* test.bmp *,但不會影響壓縮。我甚至不打算在圖像緩存中添加文件擴展名 - 爲文件名使用散列,並且最適合任何壓縮。 – Pijusn