结合两个图像使用ImageJ库

时间:2014-07-09 02:12:16

标签: java image imagej

我必须动态地从内存中的缓存字节数组生成图像,然后覆盖它们,我尝试使用ImaegJ来提高性能,但是我无法使其工作:

public class TestCombine {
    public static void main(String[] args) throws IOException {

        ByteArrayOutputStream r01Bos = new ByteArrayOutputStream();
        ImageIO.write(ImageIO.read(new File("D:/r01.png")), "png", r01Bos);
        byte[] r01Byte = r01Bos.toByteArray();
        r01Bos.close();


        ByteArrayOutputStream r02Bos = new ByteArrayOutputStream();
        ImageIO.write(ImageIO.read(new File("D:/r02.png")), "png", r02Bos);
        byte[] r02Byte = r02Bos.toByteArray();
        r02Bos.close();

        ByteArrayInputStream r01Bis = new ByteArrayInputStream(r01Byte);
        ByteArrayInputStream r02Bis = new ByteArrayInputStream(r02Byte);


        FileInfo fr01 = new FileInfo();
        fr01.width = 256;
        fr01.height = 256;
        fr01.fileType = FileInfo.ARGB;

        ImageReader reader = new ImageReader(fr01);
        ColorProcessor combine = new ColorProcessor(256, 256);

        ColorProcessor r01 = new ColorProcessor(256, 256);
        r01.setPixels(reader.readPixels(r01Bis));

        ColorProcessor r02 = new ColorProcessor(256, 256);
        r02.setPixels(reader.readPixels(r02Bis));

        combine.fill(r01);
        combine.fill(r02);

        FileInfo out = new FileInfo();
        out.width = 256;
        out.height = 256;
        out.pixels = combine.getPixels();
        out.fileType = FileInfo.ARGB;
        FileOutputStream ffos = new FileOutputStream("D:/com_imagj.png");
        new ImageWriter(out).write(ffos);
        ffos.close();

        r01Bis.close();
        r02Bis.close();

    }
}

我错过了什么吗?

0 个答案:

没有答案