private static Task GenerateAndComparePngBill(Bill bill, SeparatorType separatorType) { bill.Format.SeparatorType = separatorType; using PNGCanvas canvas = new PNGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, 288, "Arial,Helvetica"); QRBill.Draw(bill, canvas); return(VerifyImages.VerifyPng(canvas.ToByteArray())); }
public void PngSaveAs() { Bill bill = SampleData.CreateExample6(); using PNGCanvas canvas = new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 144, "Helvetica, Arial, \"Liberation Sans\""); QRBill.Draw(bill, canvas); canvas.SaveAs("qrbill.png"); }
public void PngWriteTo() { Bill bill = SampleData.CreateExample5(); using PNGCanvas canvas = new PNGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, 144, "Helvetica, Arial, \"Liberation Sans\""); QRBill.Draw(bill, canvas); MemoryStream ms = new MemoryStream(); canvas.WriteTo(ms); }
private void PngSaveAs() { Bill bill = SampleData.CreateExample6(); using (PNGCanvas canvas = new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 144, "Helvetica, Arial, Sans")) { QRBill.Draw(bill, canvas); canvas.SaveAs("qrbill.png"); } }
private void GenerateAndComparePngBill(Bill bill, SeparatorType separatorType, string expectedFileName) { bill.Format.SeparatorType = separatorType; using (PNGCanvas canvas = new PNGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, 288, "Arial,Helvetica")) { QRBill.Draw(bill, canvas); FileComparison.AssertGrayscaleImageContentsEqual(canvas.ToByteArray(), expectedFileName); } }
private void PngWriteTo() { Bill bill = SampleData.CreateExample5(); using (PNGCanvas canvas = new PNGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, 144, "Helvetica, Arial, Sans")) { QRBill.Draw(bill, canvas); MemoryStream ms = new MemoryStream(); canvas.WriteTo(ms); } }
public static byte[] generateQRcode( string account, string creditorName, string creditorAddressLine1, string creditorAddressLine2, string creditorCountryCode, decimal amount, string currency, string debtorName, string debtorAddressLine1, string debtorAddressLine2, string debtorCountryCode, string reference, string unstructuredMessage) { Bill bill = new Bill { Account = account, Creditor = new Address { Name = creditorName, AddressLine1 = creditorAddressLine1, AddressLine2 = creditorAddressLine2, CountryCode = creditorCountryCode }, Amount = amount, Currency = currency, Debtor = new Address { Name = debtorName, AddressLine1 = debtorAddressLine1, AddressLine2 = debtorAddressLine2, CountryCode = debtorCountryCode }, Reference = reference, UnstructuredMessage = unstructuredMessage }; bill.Format.OutputSize = OutputSize.QrCodeOnly; string path = "qrbill.png"; using (PNGCanvas canvas = new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 144, "Arial")) { QRBill.DrawQrBillOnly(bill, canvas); canvas.SaveAs(path); } byte[] array = File.ReadAllBytes(Path.GetFullPath(path)); return(array); }
private static ICanvas CreateCanvas(BillFormat format) { double drawingWidth; double drawingHeight; // define page size switch (format.OutputSize) { case OutputSize.QrBillOnly: drawingWidth = QrBillWidth; drawingHeight = QrBillHeight; break; case OutputSize.QrBillExtraSpace: #pragma warning disable CS0618 // Type or member is obsolete case OutputSize.QrBillWithHorizontalLine: #pragma warning restore CS0618 // Type or member is obsolete drawingWidth = QrBillWithHoriLineWidth; drawingHeight = QrBillWithHoriLineHeight; break; case OutputSize.QrCodeOnly: drawingWidth = QrCodeWidth; drawingHeight = QrCodeHeight; break; default: drawingWidth = A4PortraitWidth; drawingHeight = A4PortraitHeight; break; } ICanvas canvas; switch (format.GraphicsFormat) { case GraphicsFormat.SVG: canvas = new SVGCanvas(drawingWidth, drawingHeight, format.FontFamily); break; case GraphicsFormat.PNG: canvas = new PNGCanvas(drawingWidth, drawingHeight, format.Resolution, format.FontFamily); break; case GraphicsFormat.PDF: canvas = new PDFCanvas(drawingWidth, drawingHeight); break; default: throw new QRBillGenerationException("Invalid graphics format specified"); } return(canvas); }
public Task PngBillQrBill() { Bill bill = SampleData.CreateExample1(); byte[] png; using (PNGCanvas canvas = new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 300, "\"Liberation Sans\",Arial, Helvetica")) { bill.Format.OutputSize = OutputSize.QrBillOnly; QRBill.Draw(bill, canvas); png = canvas.ToByteArray(); } return(VerifyImages.VerifyPng(png)); }
private void PngBillQrBill() { Bill bill = SampleData.CreateExample1(); byte[] svg; using (PNGCanvas canvas = new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 300, "Arial")) { bill.Format.OutputSize = OutputSize.QrBillOnly; QRBill.Draw(bill, canvas); svg = canvas.ToByteArray(); } FileComparison.AssertGrayscaleImageContentsEqual(svg, "qrbill_ex1.png"); }
public Task PngBillA4() { Bill bill = SampleData.CreateExample3(); byte[] png; using (PNGCanvas canvas = new PNGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, 144, "Arial,\"Liberation Sans\",Helvetica")) { bill.Format.OutputSize = OutputSize.A4PortraitSheet; QRBill.Draw(bill, canvas); png = canvas.ToByteArray(); } return(VerifyImages.VerifyPng(png)); }
private void PngBillA4() { Bill bill = SampleData.CreateExample3(); byte[] png; using (PNGCanvas canvas = new PNGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, 144, "Arial,Helvetica")) { bill.Format.OutputSize = OutputSize.A4PortraitSheet; QRBill.Draw(bill, canvas); png = canvas.ToByteArray(); } FileComparison.AssertGrayscaleImageContentsEqual(png, "a4bill_ex3.png"); }
public static byte[] generateQRcode( string account, string creditorName, string creditorAddressLine1, string creditorAddressLine2, string creditorCountryCode, decimal amount, string currency, string debtorName, string debtorAddressLine1, string debtorAddressLine2, string debtorCountryCode, string reference, string unstructuredMessage) { Bill bill = new Bill { Account = account, Creditor = new Address { Name = creditorName, AddressLine1 = creditorAddressLine1, AddressLine2 = creditorAddressLine2, CountryCode = creditorCountryCode }, Amount = amount, Currency = currency, Debtor = new Address { Name = debtorName, AddressLine1 = debtorAddressLine1, AddressLine2 = debtorAddressLine2, CountryCode = debtorCountryCode }, Reference = reference, UnstructuredMessage = unstructuredMessage }; string path = "qrbill.png"; using (PNGCanvas canvas = new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 144, "Arial")) { QRBill.Draw(bill, canvas); canvas.SaveAs(path); } return(svg); }
private void ClosePngFreesResources() { Type type = typeof(PNGCanvas); FieldInfo bitmapField = type.GetField("_bitmap", BindingFlags.NonPublic | BindingFlags.Instance); Assert.NotNull(bitmapField); PNGCanvas pngCanvas; using (PNGCanvas canvas = new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 300, "Arial")) { pngCanvas = canvas; Assert.NotNull(bitmapField.GetValue(pngCanvas)); } Assert.Null(bitmapField.GetValue(pngCanvas)); }
static void Main(string[] args) { // Setup bill data Bill bill = new Bill { // creditor data Account = "CH4431999123000889012", Creditor = new Address { Name = "Robert Schneider AG", AddressLine1 = "Rue du Lac 1268/2/22", AddressLine2 = "2501 Biel", CountryCode = "CH" }, // payment data Amount = 199.95m, Currency = "CHF", // debtor data Debtor = new Address { Name = "Pia-Maria Rutschmann-Schnyder", AddressLine1 = "Grosse Marktgasse 28", AddressLine2 = "9400 Rorschach", CountryCode = "CH" }, // more payment data Reference = "210000000003139471430009017", UnstructuredMessage = "Abonnement für 2020" }; // Generate QR bill string path = "qrbill.png"; using (PNGCanvas canvas = new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 144, "Arial")) { QRBill.Draw(bill, canvas); canvas.SaveAs(path); } Console.WriteLine($"QR bill saved at {Path.GetFullPath(path)}"); }