this(image,
0, 0, image.getWidth(), image.getHeight());
} public
BufferedImageLuminanceSource(BufferedImage image, int left,
int top, int width, int height) {
super(width, height); int
sourceWidth = image.getWidth(); int
sourceHeight = image.getHeight();
if (left +
width > sourceWidth || top + height > sourceHeight) {
throw new
IllegalArgumentException( \
rectangle does not fit within image data.\ } for (int y =
top; y < top + height; y++) {
for (int x =
left; x < left + width; x++) { if
((image.getRGB(x, y) & 0xFF000000) == 0) {
image.setRGB(x, y, 0xFFFFFFFF); // = white }
} } this.image =
new BufferedImage(sourceWidth, sourceHeight,
BufferedImage.TYPE_BYTE_GRAY);
this.image.getGraphics().drawImage(image, 0, 0, null);
this.left = left;
相关推荐: