本文介绍了Java如何设置jpg质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是希望编辑一些代码,以便输出jpg质量不是默认的低质量设置
Just wanting to get some code edited so that the output jpg quality isn't the default low quality setting that
try
{
ImageIO.write(var6, "jpg", var7);
}
.....目前正在使用。
.....is using currently.
我看了一些其他java设置质量的例子,不熟悉Java我很难理解如何插入内容并重做一些例子,我已经看到使用Java来设置图像质量。
I've looked at some other java examples of setting quality, not being very familiar with Java I'm having trouble understanding how to plug stuff in and rework some examples, that I've seen on using Java to set image quality.
ImageWriteParam iwparam = new JPEGImageWriteParam(Locale.getDefault());
iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwparam.setCompressionQuality(quality);
writer.write(null, new IIOImage(image, null, null), iwparam);
这是我正在尝试工作的代码........
Here is the code I'm trying to get work........
public static String func_74292_a(File par0File, String par1Str, int par2, int par3)
{
File var4 = new File(par0File, "screenshots");
var4.mkdir();
int var5 = par2 * par3;
if (field_74293_b == null || field_74293_b.capacity() < var5)
{
field_74293_b = BufferUtils.createIntBuffer(var5);
field_74294_c = new int[var5];
}
GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
field_74293_b.clear();
GL11.glReadPixels(0, 0, par2, par3, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, field_74293_b);
field_74293_b.get(field_74294_c);
func_74289_a(field_74294_c, par2, par3);
BufferedImage var6 = new BufferedImage(par2, par3, 1);
var6.setRGB(0, 0, par2, par3, field_74294_c, 0, par2);
if (par1Str == null)
{
var7 = func_74290_a(var4);
}
else
{
var7 = new File(var4, par1Str);
}
try
{
ImageIO.write(var6, "jpg", var7);
}
catch (IOException var8)
{
;
}
Thread var7x = new Thread(new ScreenShotHelper$1());
var7x.start();
return "\u00a7aUploading Screenshot....";
}
private static File func_74290_a(File par0File)
{
String var1 = dateFormat.format(new Date()).toString();
int var2 = 1;
while (true)
{
File var3 = new File(par0File, var1 + (var2 == 1 ? "" : "_" + var2) + ".jpg");
if (!var3.exists())
{
return var3;
}
++var2;
}
}
推荐答案
最后用这个代码做了...
Finally did it with this code ...
try
{
ImageOutputStream ios = ImageIO.createImageOutputStream(var7);
Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpeg");
ImageWriter writer = iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(0.85f);
writer.setOutput(ios);
writer.write(null, new IIOImage(var6,null,null),iwp);
writer.dispose();
//ImageIO.write(var6, "jpg", var7);
}
这篇关于Java如何设置jpg质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!