保存大图像 - 光栅问题 [英] Saving large images - Raster problem

查看:132
本文介绍了保存大图像 - 光栅问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经问了一个问题如何保存大图像,我认为我走在正确的轨道上,但我仍然需要一些建议。

I already asked a Question how to save large images and I think I'm on the right track but I still need some advice.

我有一个Image 12000 x 12000,我需要保存为.png

I have an Image 12000 x 12000 and I need to save it as .png

不能使用BufferedImage。

BufferedImage can't be used.

我是已经建议使用RenderedImage接口但不知何故我无法获得所需的结果。 (我还没有使用栅格,所以我可能出错了)

I was already advised to use the RenderedImage interface but somehow I can't get the desired result. ( I haven't worked with rasters yet so probably I got something wrong )

保存图像方法的代码:

   public static void SavePanel() {

    PanelImage IMAGE = new PanelImage(panel);

    try {
        ImageIO.write(IMAGE, "png", new File(ProjectNameTxt.getText() +  ".png"));
    } catch (IOException e) {
    }

   }

PanelImage类的代码:

And code for the PanelImage class:

 public static class PanelImage implements RenderedImage {

    // some variables here

    public PanelImage(JImagePanel panel) {
       this.panel = panel;
    }

  public Raster getData(Rectangle rect) {

        sizex = (int) rect.getWidth();
        sizey += (int) rect.getHeight();
        image = null;
        image = new BufferedImage(
                (int) sizex,
                (int) sizey,
                BufferedImage.TYPE_INT_RGB);
        g2 = image.createGraphics();
        panel.paintComponent(g2);
        return image.getData();
    }

 // rest of the implemented methods - no problems here
 }

我注意到ImageIO一次请求一行像素(12000 x 1)。
这个方法有效,但我仍然需要BufferedImage中的整个图像。
每次ImageIO调用方法时我都要增加BImage的大小,否则我得到Coordinate out of bounds!exeption

I noticed that the ImageIO requests one line of pixels at a time ( 12000 x 1 ). This method is working but I still need the whole image in the BufferedImage. I have to increase the size of the BImage each time ImageIO calls the method, otherwise I get " Coordinate out of bounds! " exeption

谢谢

推荐答案

PNGJ 库可以用来读取/写入巨大的图像,因为它按顺序执行,它一次只在内存中保留一行。 (我刚才自己写了,因为我有类似的需要)

This PNGJ library can be useful to read/write huge images, because it does it sequentially, it only keeps a line in memory at a time. (I wrote it myself a while ago, because I had a similar need)

这篇关于保存大图像 - 光栅问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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