Java JAI更改JPEG分辨率
我在使用JavaJAI(JavaAdvanceImaging)API将JPEG图像的分辨率从1024x800更改为512x400时遇到了困难 我一直在使用API,并不断得到stream或Java JAI更改JPEG分辨率,java,jai,Java,Jai,我在使用JavaJAI(JavaAdvanceImaging)API将JPEG图像的分辨率从1024x800更改为512x400时遇到了困难 我一直在使用API,并不断得到stream或java.lang.OutOfMemory异常 有工作示例的任何人。这里有一个工作示例,按“原样”提供,不提供任何担保:) 下面是一个工作示例,按“原样”提供,不提供任何担保:) 这是一个使用JAI的 public void resize(String filename, RenderedOp image, do
java.lang.OutOfMemory
异常
有工作示例的任何人。这里有一个工作示例,按“原样”提供,不提供任何担保:)
下面是一个工作示例,按“原样”提供,不提供任何担保:) 这是一个使用JAI的
public void resize(String filename, RenderedOp image, double wScale, double hScale)
{
// now resize the image
ParameterBlock pb = new ParameterBlock();
pb.addSource(image); // The source image
pb.add(wScale); // The xScale
pb.add(hScale); // The yScale
pb.add(0.0F); // The x translation
pb.add(0.0F); // The y translation
RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
RenderedOp resizedImage = JAI.create("SubsampleAverage", pb, hints);
// lastly, write the newly-resized image to an
// output stream, in a specific encoding
try
{
FileOutputStream fos = new FileOutputStream(new File(filename));
JAI.create("encode", resizedImage, fos, getImageType(filename), null);
}
catch (FileNotFoundException e)
{
}
}
这是一个使用JAI的
public void resize(String filename, RenderedOp image, double wScale, double hScale)
{
// now resize the image
ParameterBlock pb = new ParameterBlock();
pb.addSource(image); // The source image
pb.add(wScale); // The xScale
pb.add(hScale); // The yScale
pb.add(0.0F); // The x translation
pb.add(0.0F); // The y translation
RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
RenderedOp resizedImage = JAI.create("SubsampleAverage", pb, hints);
// lastly, write the newly-resized image to an
// output stream, in a specific encoding
try
{
FileOutputStream fos = new FileOutputStream(new File(filename));
JAI.create("encode", resizedImage, fos, getImageType(filename), null);
}
catch (FileNotFoundException e)
{
}
}
啊,混蛋,你说得对。我想删除答案,但已经被接受了。我会投你的。啊,混蛋,你说得对。我想删除答案,但已经被接受了。我将投你的一票。