i've got qr control generating qr code , when scan phone works perfectly. i'm not able convert image can save database. i've looked on website , can't find anything, have wpf or web nothing on winforms. here how generate qr code
private void btngenerate_click(object sender, eventargs e) { string data = string.empty; var fullname = txtfirstname + " " + txtmiddlename + " " + txtlastname; if (!string.isnullorempty(txtlicencenumber.text)) { data = fullname; data += ", " + environment.newline + txtdistrict.text; data += ", " + environment.newline + txtlicencenumber.text; data += ", " + environment.newline + txtregistrationcode; } ultraqrcodebarcode1.data = data; }
and save method i'm trying convert byte code , save i'm not successful there no property image in one.
user.qrcode = imagetobytearray(ultraqrcodebarcode1.);
image converter
private byte[] imagetobytearray(string imagepath) { byte[] data = null; var fileinfo = new fileinfo(imagepath); long numbytes = fileinfo.length; var filestream = new filestream(imagepath, filemode.open, fileaccess.read); var binaryreader = new binaryreader(filestream); data = binaryreader.readbytes((int)numbytes); return data; }
ultraqrcodebarcode has saveto method. method has several overloads allowing save qr code image or memory stream. in case create memory stream , convert stream byte array this:
byte[] data; using(memorystream ms = new memorystream()) { this.ultraqrcodebarcode1.saveto(ms, imageformat.png); byte[] data = ms.toarray(); }
Comments
Post a Comment