c# - Add text from QR Code next to generated PNG -
i have made application generates me qr code in png image, have insert text qr code next qr code image.
i don't have experience using zxing library i'm thinking may contain option this...
example:
code:
namespace qr_code_with_wfa { public void createqrimage(string inputdata) { if (inputdata.trim() == string.empty) { system.windows.forms.messagebox.show("data must not empty."); } barcodewriter qrcoder = new zxing.barcodewriter { format = barcodeformat.qr_code, options = new zxing.qrcode.qrcodeencodingoptions { errorcorrection = zxing.qrcode.internal.errorcorrectionlevel.h, height = 250, width = 250 } }; string tempfilename = system.io.path.gettemppath() + inputdata + ".png"; image image; string data = inputdata; var result = qrcoder.write(inputdata); image = new bitmap(result); image.save(tempfilename); system.diagnostics.process.start(tempfilename); } }
well, zxing.barcodewriter.options
has property purebarcode
, put source text generated image when set false
.
unfortunately has no effect when format of barcode barcodeformat.qr_code
(and design).
but can draw text manually after you've generated barcode image:
var result = qrcoder.write(inputdata); using (var g = graphics.fromimage(result)) using (var font = new font(fontfamily.genericmonospace, 12)) using (var brush = new solidbrush(color.black)) using(var format = new stringformat(){alignment = stringalignment.center}) { int margin = 5, textheight = 20; var rect = new rectanglef(margin, result.height - textheight, result.width - 2 * margin, textheight); g.drawstring(inputdata, font, brush, rect, format); } result.save(tempfilename);
note can select own font size , fontfamily better suite goals.
update:
in case you're trying place text right image - have "extend" right generated image first, , draw text:
var result = qrcoder.write(inputdata); int textwidth = 200, textheight = 20; // creating new bitmap having imcreased width var img = new bitmap(result.width + textwidth, result.height); using (var g = graphics.fromimage(img)) using (var font = new font(fontfamily.genericmonospace, 12)) using (var brush = new solidbrush(color.black)) using (var bgbrush = new solidbrush(color.white)) using (var format = new stringformat() { alignment = stringalignment.near }) { // filling background white color g.fillrectangle(bgbrush, 0, 0, img.width, img.height); // drawing generated image on new 1 g.drawimage(result, new point(0,0)); // drawing text g.drawstring(inputdata, font, brush, result.width, (result.height - textheight) / 2, format); } img.save(tempfilename);
Comments
Post a Comment