private static void Draw(Image <Rgba32> image, QrCodeBlock qrCodeBlock) { CoreRectangle rectangle = new CoreRectangle( qrCodeBlock.Position.X1, qrCodeBlock.Position.Y1, qrCodeBlock.Position.Width, qrCodeBlock.Position.Height ); Rgba32 color = new Rgba32(qrCodeBlock.Color.Red, qrCodeBlock.Color.Green, qrCodeBlock.Color.Blue); image.Mutate(ctx => ctx.Fill(color, rectangle)); }
public Module(ref QrCodeBlock[,] blocks, int startX, int startY) { if (blocks == null) { throw new ArgumentNullException(nameof(blocks)); } for (int x = 0; x < BaseSize; x++) { for (int y = 0; y < BaseSize; y++) { QrCodeBlock block = blocks[startX + x, startY + y]; // -------------- // | | // | | // | | // | | // | | // -------------- bool topSide = x == 0 && y >= 0; bool leftSide = y == 0 && x >= 0; bool bottomSide = x == BaseSizeIndex && y >= 0; bool rightSide = y == BaseSizeIndex && x >= 0; // -------------- // | | // | |||||| | // | |||||| | // | |||||| | // | | // -------------- bool center = x >= 2 && x <= 4 && y >= 2 && y <= 4; if (topSide || leftSide || bottomSide || rightSide || center) { block.Black(); } else { block.White(); } } } }
public static void Main(string[] args) { DirectoryInfo directoryInfo = Directory.CreateDirectory("output"); QrCode qrCode = new QrCode(); using (Image <Rgba32> image = new Image <Rgba32>(qrCode.WidthInPixels, qrCode.HeightInPixels)) { QrCodeBlock[,] qrCodeBlocks = qrCode.Create(); for (int x = 0; x < qrCode.xMaxBlocks; x++) { for (int y = 0; y < qrCode.yMaxBlocks; y++) { QrCodeBlock qrCodeBlock = qrCodeBlocks[x, y]; Draw(image, qrCodeBlock); } } image.Save("output/qrCode.jpg"); } }