你如何克隆一个 BufferedImage [英] How do you clone a BufferedImage

查看:38
本文介绍了你如何克隆一个 BufferedImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多缓冲图像的对象,我想创建一个新对象将所有缓冲图像复制到新对象中,但是这些新图像可能会被更改,我不希望原始对象图像被更改通过更改新对象图像.

I have an object which has many bufferedimages in it, I want to create a new object copying all the bufferedimages into the new object, but these new images may be altered and i don't want the original object images to be altered by altering the new objects images.

清楚了吗?

这可以做到吗?有人可以建议一个好的方法吗?我想到了 getSubImage,但在某处读到,对子图像的任何更改都会反映回父图像.

Is this possible to do and can anyone suggest a good way to do it please? I have thought of getSubImage but read somewhere that any changes to the subimage are relected back to the parent image.

我只想能够获得一个全新的完全独立的 BufferedImage 副本或克隆

I just want to be able to get a fresh entirely separate copy or clone of a BufferedImage

推荐答案

类似的事情?

static BufferedImage deepCopy(BufferedImage bi) {
 ColorModel cm = bi.getColorModel();
 boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
 WritableRaster raster = bi.copyData(null);
 return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}

这篇关于你如何克隆一个 BufferedImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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