diff --git a/javase/src/main/java/com/google/zxing/client/j2se/MatrixToImageConfig.java b/javase/src/main/java/com/google/zxing/client/j2se/MatrixToImageConfig.java index 66eb71025..d4a563da3 100644 --- a/javase/src/main/java/com/google/zxing/client/j2se/MatrixToImageConfig.java +++ b/javase/src/main/java/com/google/zxing/client/j2se/MatrixToImageConfig.java @@ -55,8 +55,20 @@ public final class MatrixToImageConfig { } int getBufferedImageColorModel() { - // Use faster BINARY if colors match default - return onColor == BLACK && offColor == WHITE ? BufferedImage.TYPE_BYTE_BINARY : BufferedImage.TYPE_INT_ARGB; + if (onColor == BLACK && offColor == WHITE) { + // Use faster BINARY if colors match default + return BufferedImage.TYPE_BYTE_BINARY; + } + if (hasTransparency(onColor) || hasTransparency(offColor)) { + // Use ARGB representation if colors specify non-opaque alpha + return BufferedImage.TYPE_INT_ARGB; + } + // Default otherwise to RGB representation with ignored alpha channel + return BufferedImage.TYPE_INT_RGB; + } + + private static boolean hasTransparency(int argb) { + return (argb & 0xFF000000) != 0xFF000000; } }