[英]Android: How can I save image files that are not (JPEG & PNG)? [after rotate]
I am trying to rotate an image from sdcard and then save back to sdcard. 我正在尝试从sdcard旋转图像,然后保存回sdcard。
I can do that for ".jpg" format by using ExifInterface class: 我可以通过使用ExifInterface类来实现“ .jpg”格式:
exif = new ExifInterface(filepath);
exif.setAttribute(ExifInterface.TAG_ORIENTATION, Integer.toString(orientation));
exif.saveAttributes();
For ".png" files, I would have to actually rotate and save: 对于“ .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);
What about ".bmp", ".tiff", ".gif" ?? 那么“ .bmp”,“。tiff”,“。gif”呢?
It seems like CompressFormat only supports 'CompressFormat.PNG' and 'CompressFormat.JPG'. 看来CompressFormat仅支持'CompressFormat.PNG'和'CompressFormat.JPG'。
Is this limitation? 有这个限制吗?
Yes Limited To JPG , PNG , WEBP 是仅限JPG,PNG,WEBP
http://developer.android.com/reference/android/graphics/Bitmap.CompressFormat.html http://developer.android.com/reference/android/graphics/Bitmap.CompressFormat.html
Hey just give the name to .bmp 嘿,只需给.bmp命名
Do this: 做这个:
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**")
it'll sound that IM JUST FOOLING AROUND but try it once it'll get saved in bmp foramt..Cheers 听起来好像IM刚到处都是,但是一旦将它保存在bmp格式中,请尝试一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.