简体   繁体   English

如何在Java中减小图像大小

[英]How to reduce the size of image in java

Please help some one for how to reduce the size of image in java 请帮助一些如何减少java中图像的大小

my problem is 我的问题是

i am taking one image as input for java program and taking output as .bmp image 我将一个图像作为Java程序的输入并将输出作为.bmp图像

for creating new image i am using the following code 用于创建新图像,我正在使用以下代码

for (int i = 0; i < width; i++)     
         {    
              for (int j = 0; j < height; j++)   
              {  
                Color c = new Color(color2[i][j], color2[i][j], color2[i][j]);  
                image1.setRGB(i, j, c.getRGB());   
              }     
          }   
ImageIO.write(image1, "bmp", new File("hh5_binary_Adjust.bmp"));

but if i use the above code i am getting 6.5 mb size for one A4 size paper so please help me to get a minimum length of image without modifying the file extension that is bmp 但是,如果我使用上面的代码,我一张A4尺寸的纸张将获得6.5 mb的大小,因此请帮助我获得最小图像长度,而无需修改bmp的文件扩展名

If you want to reduce the resolution, there isn't a good way to do this and get a really crisp output image without using an external library. 如果要降低分辨率,则没有一种好方法,而无需使用外部库即可获得非常清晰的输出图像。 I recommend imgscalr . 我推荐imgscalr I've had fantastic results with it. 我取得了惊人的成绩。

But please be aware that the main reason you have a large file size is that you're using BMP as the output format! 但是请注意,文件较大的主要原因是您将BMP用作输出格式! If you change that, you'll massively reduce the file size easily and cheaply. 如果您进行更改,则可以轻松,廉价地大量减少文件大小。 I'd go with JPG for photos, or PNG for graphics. 我会用JPG拍摄照片,或使用PNG拍摄图形。

The ImageIO class will save to either of those with no trouble. ImageIO类将ImageIO保存到任何一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM