旋转图像文件,而无需改变文件大小 [英] Rotate an image file without changing file size

查看:119
本文介绍了旋转图像文件,而无需改变文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不改变文件大小旋转图像文件(照片):

I want to rotate an image file (photo) without changing file size :


  • 我创建Bitmap.de codeFILE位图

  • 我应用旋转:

  • I create a bitmap with Bitmap.decodeFile
  • I apply the rotation :

Matrix matrix = new Matrix();
matrix.postRotate(90);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);


  • 我保存的位图与一个文件:

  • I save bitmap into a file with :

    bitmap.compress(CompressFormat.JPEG, 100, stream);
    


  • 但我的原始文件的大小增加了一倍!

    but the size of my original file has doubled !!

    推荐答案

    在加载的图像是EN codeD在一定的格式(如JPEG),并具有一定的COM pression质量(如质量较好的equals更大的文件大小)。当你保存它旋转,您指定一个潜在完全不同的格式和COM pression质量,因此大小差异了。

    The image you load is encoded in a certain format (e.g. JPEG) and with a certain compression quality (where better quality equals larger file size). When you save it after rotating, you are specifying a potentially completely different format and compression quality, hence the size difference.

    我不认为这是可以保证相同的大小,除非输入和输出文件uncom pressed位图的任何方式,但你也许可以,至少揣摩使用什么格式和质量当你保存文件再次使用bitmap.com preSS原始图像和使用这些设置。这应该给你在同一个球场的文件大小至少为。

    I don't think there is any way you can guarantee the same size unless both the input and output files are uncompressed bitmaps, but you can probably at least try to figure out what format and quality was used for the original image and use those settings when you save the file again using bitmap.compress . That should give you a file size in the same ballpark at least.

    这篇关于旋转图像文件,而无需改变文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆