diff --git a/QRCoder/BitmapByteQRCode.cs b/QRCoder/BitmapByteQRCode.cs index 40045e5d..529cc5cc 100644 --- a/QRCoder/BitmapByteQRCode.cs +++ b/QRCoder/BitmapByteQRCode.cs @@ -59,7 +59,7 @@ public byte[] GetGraphic(int pixelsPerModule, byte[] darkColorRgb, byte[] lightC var bmp = new List(); //header - bmp.AddRange(new byte[] { 0x42, 0x4D, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00 }); + bmp.AddRange(new byte[] { 0x42, 0x4D, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00 }); //width bmp.AddRange(IntTo4Byte(sideLength)); @@ -68,6 +68,7 @@ public byte[] GetGraphic(int pixelsPerModule, byte[] darkColorRgb, byte[] lightC //header end bmp.AddRange(new byte[] { 0x01, 0x00, 0x18, 0x00 }); + bmp.AddRange(new byte[24]); //draw qr code for (var x = sideLength - 1; x >= 0; x -= pixelsPerModule) @@ -93,12 +94,16 @@ public byte[] GetGraphic(int pixelsPerModule, byte[] darkColorRgb, byte[] lightC } } - //finalize with terminator - bmp.AddRange(new byte[] { 0x00, 0x00 }); - + // write filesize in header + var bmpFileSize = IntTo4Byte(bmp.Count); + for (int i = 0; i < bmpFileSize.Length; i++) + { + bmp[2 + i] = bmpFileSize[i]; + } return bmp.ToArray(); } + /// /// Converts a hex color string to a byte array. /// @@ -121,9 +126,11 @@ private byte[] HexColorToByteArray(string colorString) /// Returns the integer as a 4-byte array. private byte[] IntTo4Byte(int inp) { - byte[] bytes = new byte[2]; + byte[] bytes = new byte[4]; unchecked { + bytes[3] = (byte)(inp >> 24); + bytes[2] = (byte)(inp >> 16); bytes[1] = (byte)(inp >> 8); bytes[0] = (byte)(inp); }