Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Bitmap header #565

Merged
merged 3 commits into from
Jun 22, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions QRCoder/BitmapByteQRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
var bmp = new List<byte>();

//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));
Expand All @@ -68,6 +68,7 @@

//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)
Expand All @@ -92,13 +93,17 @@
}
}
}

//finalize with terminator
bmp.AddRange(new byte[] { 0x00, 0x00 });


Check failure on line 96 in QRCoder/BitmapByteQRCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 96 in QRCoder/BitmapByteQRCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 96 in QRCoder/BitmapByteQRCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 96 in QRCoder/BitmapByteQRCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 96 in QRCoder/BitmapByteQRCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting

Check failure on line 96 in QRCoder/BitmapByteQRCode.cs

View workflow job for this annotation

GitHub Actions / format

Fix formatting
// 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();
}


/// <summary>
/// Converts a hex color string to a byte array.
/// </summary>
Expand All @@ -121,9 +126,11 @@
/// <returns>Returns the integer as a 4-byte array.</returns>
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);
}
Expand Down
Loading