提高在Java中使用缩放JPEG图像质量 [英] Improving jpeg image quality using scaling in java

查看:1288
本文介绍了提高在Java中使用缩放JPEG图像质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成使用phantomjs的JPG图像。我想用影像尺寸600x400px和144 DPI / PPI。

但我只能生成一个为72dpi形象。所以,我想产生在72 dpi的1200x800px尺寸的图像,然后将其调整到600x400px。
所以我的想法是,

  1200x800像素具有DPI 72

所以,

  600x400px将有DPI 72 * 2 = 144(因为二分之一千二百= 600px的800/2 = 400像素)

我用java。但每当我调整我的图像质量变少。

途径我想:


  1. 我试图操纵图像的元数据信息,如下面的帖子解释,但还是它给图像质量差。

    <一个href=\"http://stackoverflow.com/questions/13977858/increasing-resolution-and-reducing-size-of-an-image-in-java\">Increasing分辨率和Java中的图像减小尺寸

    写dpi的元数据Java中的jpeg图片


  2. 我试着用的AffineTransform在下面的帖子,仍不满意的结果给出:

    Java的图像缩放提高质量?


我使用了错误的方法呢?如果是的话,请提出了一些方案。
如果该方法是正确的,那么请指导我如何正确实现它?

更新

我不希望减少没有。的像素。我想保持无。像素相同,但降低图像的高度/宽度同时增加了DPI。
例如,在具有分辨率72 1200x800px的图像,我将其降低到600x400像素,同时增加DPI 144。
所以,如果你看到了没有像素的相同和图像具有更高的dpi值。



  

终于解决它利用iText渲染器。请参考以下职位
  利用iText缩放大图像,以提高分辨率。


  
  

  
  

利用iText 图像质量



解决方案

我解决它利用iText。

 文件文件=新的文件(demo.png);
图片IMG = Image.getInstance(file.getName());
img.scaleAbsolute(宽度,高度); //其中宽度,高度是减小的宽度,高度;在我的情况600,400。

看了一遍图片类,并使用 scaleAbsolute ()。
有关详细信息,请阅读这篇文章:
利用iText 图像质量

PS:这仅是有益的,如果你正试图把图像中的PDF。
如果有人知道如何IMG转换为PNG文件,然后请评论。

I am generating a jpg image using phantomjs. I want image with 600x400px dimension and 144 dpi/ppi.

But I am only able to generate a image with 72dpi. So, I am trying to generate the image with 1200x800px dimensions in 72 dpi and then resizing it to 600x400px. so my idea is,

1200x800 px has dpi 72

so,

600x400px will have dpi 72*2 = 144   (because 1200/2=600px , 800/2=400px )

I am using java. But whenever I resize my image the quality becomes less.

Approaches I tried :

  1. I tried to manipulate the metadata information of image as explained in the post below, but still it gives image with poor quality.

    Increasing Resolution and Reducing Size of an Image in Java

    Write dpi metadata to a jpeg image in Java

  2. I tried using AffineTransform as given in following post, still not satisfied with results:

    Java image scaling improve quality?

Am I using a wrong approach? If yes, then please suggest some alternatives. If the approach is right then please guide me on how to implement it correctly?

UPDATE

I don't want to reduce the no. of pixels. I want to keep the no. of pixels same but reduce the height/width of image while increasing the dpi. example, In an image of 1200x800px having 72 dpi, I will reduce it to 600x400 px while increasing dpi to 144 . So , if you see the no of pixels are same and the image has higher dpi value.


Finally solved it using itext renderer. Refer to the following post on using itext for scaling the large image to increase resolution.


Image Quality using Itext

解决方案

I solved it using Itext.

File file = new File("demo.png");
Image img = Image.getInstance(file.getName());
img.scaleAbsolute(width, height); //where width,height is the reduced width,height; in my case 600,400.

Read it through Image class and use scaleAbsolute(). For more details please read this post: Image Quality using Itext

PS: This is only helpful if you are trying to put image in pdf. If anyone knows how to convert img to a png file then please comment.

这篇关于提高在Java中使用缩放JPEG图像质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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