简体   繁体   English

Android:如何保存非JPEG和PNG格式的图像文件? [旋转后]

[英]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? 有这个限制吗?

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.

相关问题 如何在 Android 中将 PictureDrawable 保存为 JPEG/PNG 文件 - How to Save a PictureDrawable as a JPEG/PNG file in Android Android Eclipse如何将渲染的GLsurfaceView保存为* .png图像 - Android Eclipse How can i save rendered GLsurfaceView as *.png image 有什么方法可以将 GIF 图像分割成帧并在 Android 中将其另存为 JPEG 或 PNG - Is there any way to split GIF image into frames and save it as JPEG or PNG in Android 如何在Android中旋转轮子(图像PNG) - How to rotate a wheel (image png) in android 如何在android的服务器中上传多个选定的文件(即.doc、pdf、jpeg、png) - How to upload multiple selected files (i.e..doc,pdf,jpeg,png) in server at android Android:如何将预览框保存为jpeg图像? - Android: How to save a preview frame as jpeg image? 如何以编程方式检查Android中的图像(PNG,JPEG)是否已损坏或不受支持? - How do I programmatically check whether an image (PNG, JPEG) is corrupted or unsupported in android? 如何在android中将图像格式从JPEG更改为PNG? - How to change the image format from JPEG to PNG in android? 如何在Android 5.0中删除旋转位图图像后的黑色背景 - How can i remove black background of after rotate Bitmap image in android 5.0 捕获android webview图像并保存到png / jpeg - Capturing android webview image and saving to png/jpeg
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM