Easy. With a catch (as always).
You have to change the pixel size of the whole bitmap canvas, which is set in the Gdip_CreateBitmap() call, to achieve similar proportions to an A4 page. Also, since default pixel color is black, you have to adjust Gdip_FillRectangle() once again to be sure to paint the whole canvas white (not just part of it).
It is important to notice that i said similar proportions (not similar size) because pixels have no set size in real world. You cannot measure an A4 page in pixels. A picture that was printed to be 10cm long in a paper may have a width of 100 pixels in lower resolution and a width of 100,000 pixels in higher resolution before printing. But you can use pixels in similar proportions to get an idea of how the picture will look like once printed in an A4 paper.
So let's make our canvas have a width of 2100 pixels and a height of 2970 pixels. That means a 300x300 pixels picture will take roughly a tenth of the height and a seventh of the width. It will also be in a set proportion of 10 pixels per milimeter of the A4 page, which is fair enougth.
change this line:
Code: Select all
pBitmap := Gdip_CreateBitmap((MATRIX_TO_PRINT.MaxIndex() + 8) * PixelSize, (MATRIX_TO_PRINT.MaxIndex() + 8) * PixelSize) ; Adding 8 pixels to the width and height here as a "quiet zone" for the image. This serves to improve the printed code readability. QR Code specs require the quiet zones to surround the whole image and to be at least 4 modules wide (4 on each side = 8 total width added to the image). Don't forget to increase this number accordingly if you plan to change the pixel size of each module.
to this:
Code: Select all
pBitmap := Gdip_CreateBitmap( 2100, 2970)
And also this line:
Code: Select all
Gdip_FillRectangle(G, pBrush, 0, 0, (MATRIX_TO_PRINT.MaxIndex() + 8) * PixelSize, (MATRIX_TO_PRINT.MaxIndex() + 8) * PixelSize) ; Same as above.
to this:
Code: Select all
Gdip_FillRectangle(G, pBrush, 0, 0, 2100, 2970)
And you should get something close enought to your picture, with the text message being able to take the whole width of the page.
The QR Matrix will be positioned right below it though. To make it go lower or to the right of the page, you have to add the ammount of pixels to jump in each direction to the Gdip_SetPixel()s x and y parameters on each call.
The math to achieve the center of the page is simple.
You take the width of the page, subtract the width of your image and divide the result by 2 (i considered a QR Matrix of 290 pixels total width).
(2100 - 290) / 2 = 905
Add it to the X position of the Gdip_SetPixel calls.
Also, take the height of the page, subtract the height of your image and divide the result by 2 (i considered a QR Matrix of 290 pixels total height).
(2970 - 290) / 2 = 1340
Add it to the Y position of the Gdip_SetPixel calls.
Thus, this line (only 1 line):
Code: Select all
Gdip_SetPixel(pBitmap, (CURRENT_COLUMN * PixelSize) + (3*PixelSize) - 1 + A_Index, (CURRENT_ROW * PixelSize) + (3*PixelSize) - 1 + CURRENT_REDIMENSION_ROW, 0xFF000000)
Should become this:
Code: Select all
Gdip_SetPixel(pBitmap, (CURRENT_COLUMN * PixelSize) + (3*PixelSize) - 1 + A_Index + 905, (CURRENT_ROW * PixelSize) + (3*PixelSize) - 1 + CURRENT_REDIMENSION_ROW + 1340, 0xFF000000)
And this line (yes, this is ANOTHER line!):
Code: Select all
Gdip_SetPixel(pBitmap, (CURRENT_COLUMN * PixelSize) + (3*PixelSize) - 1 + A_Index, (CURRENT_ROW * PixelSize) + (3*PixelSize) -1 + CURRENT_REDIMENSION_ROW, 0xFFFFFFFF)
Should become this:
Code: Select all
Gdip_SetPixel(pBitmap, (CURRENT_COLUMN * PixelSize) + (3*PixelSize) - 1 + A_Index + 905, (CURRENT_ROW * PixelSize) + (3*PixelSize) -1 + CURRENT_REDIMENSION_ROW + 1340, 0xFFFFFFFF)
Those changes should yield something close to what you are looking for.