mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Issue 1059 treat transparent areas as white
git-svn-id: https://zxing.googlecode.com/svn/trunk@2028 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
fe9bdc6974
commit
f5df4e5adc
|
@ -47,6 +47,18 @@ public final class BufferedImageLuminanceSource extends LuminanceSource {
|
||||||
if (left + width > sourceWidth || top + height > sourceHeight) {
|
if (left + width > sourceWidth || top + height > sourceHeight) {
|
||||||
throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
|
throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The color of fully-transparent pixels is irrelevant. They are often, technically, fully-transparent
|
||||||
|
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
|
||||||
|
// barcode image. Force any such pixel to be white:
|
||||||
|
for (int i = top; i < top + height; i++) {
|
||||||
|
for (int j = left; j < left + width; j++) {
|
||||||
|
if ((image.getRGB(i, j) & 0xFF000000) == 0) {
|
||||||
|
image.setRGB(i, j, 0xFFFFFFFF); // = white
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create a grayscale copy, no need to calculate the luminance manually
|
// Create a grayscale copy, no need to calculate the luminance manually
|
||||||
this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY);
|
this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY);
|
||||||
this.image.getGraphics().drawImage(image, 0, 0, null);
|
this.image.getGraphics().drawImage(image, 0, 0, null);
|
||||||
|
|
Loading…
Reference in a new issue