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

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

问题描述

Hi我有一个对象,其中有很多的缓冲图像,我想创建一个新的对象复制所有的缓冲图像到新的对象,但这些新的图像可能会改变,我不想改变原始对象图像



这是可能的,任何人都可以建议好的方法来做呢?
我已经考虑过getSubImage,但是在某处读取对子图像的任何更改都会返回到父图像。



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



chris wade

解决方案

这样的东西?

  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);
}


Hi 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 dont want the original object images to be altered by altering the new objects images.

is that clear?

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.

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

chris wade

解决方案

Something like this?

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天全站免登陆