public Image Encode ( string Code ) { QREncoder Encoder = new QREncoder(); Encoder.Encode( ErrorCorrection.H, Code ); Image image = QRCodeToBitmap.CreateBitmap( Encoder, 4, 8 ); return image; }
public override Image Encode(Store Code) { string json = JsonConvert.SerializeObject(new JsonFormat(Code)); QREncoder Encoder = new QREncoder(); Encoder.Encode(ErrorCorrection.H, json); Image image = QRCodeToBitmap.CreateBitmap(Encoder, 4, 8); return(image); }
/// <summary> /// Create QR Code image /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Event arguments</param> private void OnEncode(object sender, EventArgs e) { // get error correction code ErrorCorrection ErrorCorrection = (ErrorCorrection)ErrorCorrectionComboBox.SelectedIndex; // get data for QR Code string Data = DataTextBox.Text.Trim(); if (Data.Length == 0) { MessageBox.Show("Data must not be empty."); return; } // save state ProgramState.State.EncodeErrorCorrection = ErrorCorrection; ProgramState.State.EncodeData = Data; ProgramState.SaveState(); // disable buttons EnableButtons(false); try { // multi segment if (SeparatorCheckBox.Checked && Data.IndexOf('|') >= 0) { string[] Segments = Data.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); // encode data QRCodeEncoder.Encode(ErrorCorrection, Segments); } // single segment else { // encode data QRCodeEncoder.Encode(ErrorCorrection, Data); } // create bitmap QRCodeImage = QRCodeToBitmap.CreateBitmap(QRCodeEncoder, 4, 8); } catch (Exception Ex) { MessageBox.Show("Encoding exception.\r\n" + Ex.Message); } // enable buttons EnableButtons(true); // repaint panel Invalidate(); return; }
public void CreateQR(Store store) { string path = Utils.GetStoresPath() + store.storeName + ".png"; string json = JsonConvert.SerializeObject(store); QRStore qrStore = new QRStore(store.idStore, store.storeName); qrStore.products = ConvertStoreProductListToProductList(store.products); _QRencoder.Encode(ErrorCorrection.H, json); Bitmap QRStore = QRCodeToBitmap.CreateBitmap(_QRencoder, 4, 8); FileStream FS = new FileStream(path, FileMode.Create); QRStore.Save(FS, ImageFormat.Png); FS.Close(); Logger.Log(String.Format("Image succesfully created for store: {0}", qrStore.storeName)); }
private void OnSaveClick(object sender, EventArgs e) { // reset some variables int CameraDistance = 0; int CameraRotation = 0; int ImageWidth = 0; int ImageHeight = 0; int QRImageDimension = 0; int QRCodePosX = 0; int QRCodePosY = 0; int ViewXRotation = 0; ErrorSpotControl ErrorControl = ErrorSpotControl.None; int ErrorDiameter = 0; int ErrorSpots = 0; // make sure module size is not zero if (QRModuleSize == 0) { MessageBox.Show("Module size must be defined"); return; } // make sure quiet zone is not zero if (QRQuietZone < 0) { MessageBox.Show("Quiet zone must be defined"); return; } // image dimension QRImageDimension = QRCode.QRCodeImageDimension(QRModuleSize, QRQuietZone); // display qr code over image made with a brush if (BrushRadioButton.Checked) { // area width if (!int.TryParse(BrushWidthTextBox.Text.Trim(), out ImageWidth) || ImageWidth <= 0 || ImageWidth >= 100000) { MessageBox.Show("Brush background width is invalid"); return; } // area width if (!int.TryParse(BrushHeightTextBox.Text.Trim(), out ImageHeight) || ImageHeight <= 0 || ImageHeight >= 100000) { MessageBox.Show("Brush background height is invalid"); return; } } // display qr code over an image if (ImageRadioButton.Checked) { // image must be defined if (ImageBitmap == null) { MessageBox.Show("Background image must be defined"); return; } ImageWidth = ImageBitmap.Width; ImageHeight = ImageBitmap.Height; } if (!NoneRadioButton.Checked) { // QR code position X if (!int.TryParse(QRCodePosXTextBox.Text.Trim(), out QRCodePosX) || QRCodePosX <= 0 || QRCodePosX >= ImageWidth) { MessageBox.Show("QR code position X must be within image width"); return; } // QR code position Y if (!int.TryParse(QRCodePosYTextBox.Text.Trim(), out QRCodePosY) || QRCodePosY <= 0 || QRCodePosY >= ImageHeight) { MessageBox.Show("QR code position Y must be within image height"); return; } // rotation if (!int.TryParse(ImageRotationTextBox.Text.Trim(), out CameraRotation) || CameraRotation < -360 || CameraRotation > 360) { MessageBox.Show("Rotation must be -360 to 360"); return; } // camera distance if (!int.TryParse(CameraDistanceTextBox.Text.Trim(), out CameraDistance) || CameraDistance < 10 * QRModuleSize) { MessageBox.Show("Camera distance is invalid"); return; } // Axis X Rotation if (!int.TryParse(CameraViewRotationTextBox.Text.Trim(), out ViewXRotation) || ViewXRotation > 160 || ViewXRotation < -160) { MessageBox.Show("View X rotation invalid"); return; } } // error if (!ErrorNoneRadioButton.Checked) { if (ErrorWhiteRadioButton.Checked) { ErrorControl = ErrorSpotControl.White; } else if (ErrorBlackRadioButton.Checked) { ErrorControl = ErrorSpotControl.Black; } else { ErrorControl = ErrorSpotControl.Alternate; } int MaxSpotDiameter = QRCode.QRCodeImageDimension(QRModuleSize, QRQuietZone) / 8; if (!int.TryParse(ErrorDiameterTextBox.Text.Trim(), out ErrorDiameter) || ErrorDiameter <= 0 || ErrorDiameter > MaxSpotDiameter) { MessageBox.Show("Error diameter is invalid"); return; } if (!int.TryParse(ErrorNumberTextBox.Text.Trim(), out ErrorSpots) || ErrorSpots <= 0 || ErrorSpots > 100) { MessageBox.Show("Number of error spots is invalid"); return; } } // get file name string FileName = SaveFileName(); if (FileName == null) { return; } // output bitmap Bitmap OutputBitmap; // display QR Code image by itself if (NoneRadioButton.Checked) { OutputBitmap = QRCodeToBitmap.CreateBitmap(QRCode, QRModuleSize, QRQuietZone); } else { if (ImageRadioButton.Checked) { OutputBitmap = new Bitmap(ImageBitmap); } else { // create area brush Brush AreaBrush = (int)HatchStyleComboBox.SelectedItem < 0 ? (Brush) new SolidBrush(BrushColorButton.BackColor) : (Brush) new HatchBrush((HatchStyle)((int)HatchStyleComboBox.SelectedItem), Color.Black, BrushColorButton.BackColor); // create picture object and and paint it with the brush OutputBitmap = new Bitmap(ImageWidth, ImageHeight); Graphics Graphics = Graphics.FromImage(OutputBitmap); Graphics.FillRectangle(AreaBrush, 0, 0, ImageWidth, ImageHeight); } if (ViewXRotation == 0) { OutputBitmap = QRCodeToBitmap.CreateBitmap(QRCode, QRModuleSize, QRQuietZone, OutputBitmap, QRCodePosX, QRCodePosY, CameraRotation); } else { OutputBitmap = QRCodeToBitmap.CreateBitmap(QRCode, QRModuleSize, QRQuietZone, OutputBitmap, QRCodePosX, QRCodePosY, CameraRotation, CameraDistance, ViewXRotation); } } // Error spots if (ErrorControl != ErrorSpotControl.None) { QRCodeToBitmap.AddErrorSpots(OutputBitmap, ErrorControl, ErrorDiameter, ErrorSpots); } // save image FileStream FS = new FileStream(FileName, FileMode.Create); OutputBitmap.Save(FS, (ImageFormat)ImageFormatComboBox.SelectedItem); FS.Close(); // start image editor Process.Start(FileName); return; }