如何克隆图片? [英] How to clone Image?

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

问题描述

我有一张图片。我需要准确复制它并将其保存到BufferedImage,但是没有Image.clone()。事情应该在计算循环内部,所以它应该非常快,没有逐像素复制。执行此操作的性能方法最好的是什么?

I have an Image. I need to make a exactly copy of it and save it to BufferedImage, but there is no Image.clone(). The thing should be inside a calculating loop and so it should be really fast, no pixel-by-pixel copying. What's the best in perfomance method to do this?

推荐答案

你可以绘制到一个缓冲的图像,所以制作一个空白 bufferedImage ,创建一个图形上下文从它开始,并将原始图像绘制到它。

You can draw to a buffered image, so make a blank bufferedImage, create a graphics context from it, and draw your original image to it.

BufferedImage copyOfImage = 
   new BufferedImage(widthOfImage, heightOfImage, BufferedImage.TYPE_INT_RGB);
Graphics g = copyOfImage.createGraphics();
g.drawImage(originalImage, 0, 0, null);

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

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