Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JAI更改JPEG分辨率_Java_Jai - Fatal编程技术网

Java JAI更改JPEG分辨率

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

我在使用JavaJAI(JavaAdvanceImaging)API将JPEG图像的分辨率从1024x800更改为512x400时遇到了困难

我一直在使用API,并不断得到stream或
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)
    {
    }
}

啊,混蛋,你说得对。我想删除答案,但已经被接受了。我会投你的。啊,混蛋,你说得对。我想删除答案,但已经被接受了。我将投你的一票。