BufferedImage的getSubimage()到底做什么? [英] What exactly does getSubimage() of BufferedImage do?

查看:443
本文介绍了BufferedImage的getSubimage()到底做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理绘图应用程序。整个绘图始终存储在 BufferedImage 对象中(使用恒定的更新循环)。让我们称之为 drawingArea

I'm working on a 'drawing' application. The entire 'drawing' is constantly stored in a BufferedImage object (using a constant update loop). Let's call it drawingArea.

我正在使用 BufferedImage实现选择工具类' getSubimage()方法。用户使用此工具选择一个图形区域,并将其粘贴到图形上的任何地方。

I'm implementing a selection tool, using the BufferedImage class' getSubimage() method. The user uses this tool to select an area of the drawing, and paste it anywhere on the drawing.

用户通过拖动鼠标以及在她释放鼠标,所选区域存储在 BufferedImage 中。这是通过调用 drawingArea getSubimage(/ *所选矩形区域的属性* /)来完成的,并且将返回值放入 BufferedImage (我们将其称为 selectedArea )。

The user selects an area by dragging the mouse, and when he/she releases the mouse, the selected area is stored in a BufferedImage. This is done by calling drawingArea's getSubimage( /* properties of the selected rectangular area */ ) method, and putting the returned value inside that BufferedImage (let's call it selectedArea).

此操作仅执行一次(又名,一旦 selectedArea 中存在一个值,则没有任何代码会为 selectedArea 分配新内容。

This operation is done only once (aka, once there's a value inside selectedArea, there isn't any code that assigns anything new to selectedArea).

但是,我发现了(并且肯定它),则存储在 selectedArea 中的值确实发生了变化-存储的图像已更新!

However, I found out (and am certain of it), that the value stored in selectedArea does change - the image it stores gets updated!

含义:如果用户选择一个区域(此时将保存该区域的副本图像),然后在该区域内绘制,然后然后粘贴图片-粘贴的图片将是在绘图后的 ,而不是在绘图之前。

Meaning: If the user selects an area (at this point an image which is a copy of this area is saved), then draws something inside that area, and then pastes the picture - the picture pasted would be the one after the drawing, and not before it.

怎么可能? getSubimage()返回的 BufferedImage 是否会在原始更新时更新? (又是从中复制的区域)?
这似乎很愚蠢,但在目前看来,这似乎是唯一的选择。

How can this be? Does getSubimage() return a BufferedImage that gets updated when it's origin is updated? (aka the area that it was copied from)? This seems silly but at this point it seems to me like the only option.

推荐答案

如有疑问,请检查文档:

When in doubt, check the documentation:


返回由指定矩形区域定义的子图像。 返回的BufferedImage与原始图像共享相同的数据数组。

换句话说,是的,进行了修改在原始图片或子图片中都可以看到。

In other words, yes, modification in either the original or the sub image is seen in the other.

这篇关于BufferedImage的getSubimage()到底做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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