Android:我如何保存不是(JPEG&PNG)的图像文件? [旋转后]

问题描述:

我想从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'。

这是限制吗?

嘿只是给为.bmp

做到这一点的名字:

ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
_bitmapScaled.compress(Bitmap.CompressFormat.PNG, 40, bytes); 

//you can create a new file name "test.BMP" in sdcard folder. 
File f = new File(Environment.getExternalStorageDirectory() 
         + File.separator + "**test.bmp**") 

它会声音,我只是愚蠢的周围,但尝试一次,它会得到保存在bmp文件..干杯

+0

文件ex紧张局势只是一个惯例。它会将PNG图像保存为* test.bmp *,但不会影响压缩。我甚至不打算在图像缓存中添加文件扩展名 - 为文件名使用散列,并且最适合任何压缩。 – Pijusn