Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = @"PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|Encapsuled PostScript (*.eps)|*.eps|SVG (*.svg)|*.svg";
            saveFileDialog.FileName = Path.GetFileName(GetFileNameProposal());
            saveFileDialog.DefaultExt = "png";

            if (saveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            QrEncoder encoder = new QrEncoder();
            QrCode qrCode;
            byte[] byteArray = new byte[] { 34, 54, 90, 200 };
            if (!encoder.TryEncode(byteArray, out qrCode))
                return;
            if (saveFileDialog.FileName.EndsWith("eps"))
            {
                BitMatrix matrix = qrCode.Matrix;

                // Initialize the EPS renderer
                var renderer = new EncapsulatedPostScriptRenderer(
                    new FixedModuleSize(6, QuietZoneModules.Two), // Modules size is 6/72th inch (72 points = 1 inch)
                    new FormColor(Color.Black), new FormColor(Color.White));

                using (var file = File.Open(saveFileDialog.FileName, FileMode.CreateNew))
                {
                    renderer.WriteToStream(matrix, file);
                }
            }
            else if (saveFileDialog.FileName.EndsWith("svg"))
            {
                BitMatrix matrix = qrCode.Matrix;

                // Initialize the EPS renderer
                var renderer = new SVGRenderer(
                    new FixedModuleSize(6, QuietZoneModules.Two), // Modules size is 6/72th inch (72 points = 1 inch)
                    new FormColor(Color.FromArgb(150, 200, 200, 210)), new FormColor(Color.FromArgb(200, 255, 155, 0)));

                using (var file = File.OpenWrite(saveFileDialog.FileName))
                {
                    renderer.WriteToStream(matrix, file, false);
                }
            }
            else
            {
                GraphicsRenderer gRender = new GraphicsRenderer(new FixedModuleSize(30, QuietZoneModules.Four));
                BitMatrix matrix = qrCode.Matrix;
                using (FileStream stream = new FileStream(saveFileDialog.FileName, FileMode.Create))
                {
                    gRender.WriteToStream(matrix, ImageFormat.Png, stream, new Point(600, 600));
                }
            }
        }
Exemple #2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
        	
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = @"PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|Encapsuled PostScript (*.eps)|*.eps";
            saveFileDialog.FileName = Path.GetFileName(GetFileNameProposal());
            saveFileDialog.DefaultExt = "png";

            if (saveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

			if (saveFileDialog.FileName.EndsWith("eps"))
			{
                BitMatrix matrix = qrCodeGraphicControl1.GetQrMatrix();

                // Initialize the EPS renderer
                var renderer = new EncapsulatedPostScriptRenderer(
                    new FixedModuleSize(6, QuietZoneModules.Two), // Modules size is 6/72th inch (72 points = 1 inch)
                    new EPSFormColor(Color.Black), new EPSFormColor(Color.White));

                using (var file = File.OpenWrite(saveFileDialog.FileName))
                {
                    renderer.WriteToStream(matrix, file);
                }
			}
			else
			{

                DrawingBrushRenderer dRender = new DrawingBrushRenderer(new FixedModuleSize(5, QuietZoneModules.Four));
                BitMatrix matrix = qrCodeGraphicControl1.GetQrMatrix();
                using (FileStream stream = new FileStream(saveFileDialog.FileName, FileMode.Create))
                {
                    dRender.WriteToStream(matrix, ImageFormatEnum.PNG, stream);
                }

                //WriteableBitmapRenderer wRender = new WriteableBitmapRenderer(new FixedModuleSize(15, QuietZoneModules.Four));
                //BitMatrix matrix = qrCodeGraphicControl1.GetQrMatrix();
                //using (FileStream stream = new FileStream(saveFileDialog.FileName, FileMode.Create))
                //{
                //    wRender.WriteToStream(matrix, ImageFormatEnum.PNG, stream);
                //}

                //GraphicsRenderer gRender = new GraphicsRenderer(new FixedModuleSize(15, QuietZoneModules.Four));
                //BitMatrix matrix = qrCodeGraphicControl1.GetQrMatrix();
                //using (FileStream stream = new FileStream(saveFileDialog.FileName, FileMode.Create))
                //{
                //    gRender.WriteToStream(matrix, ImageFormat.Png, stream);
                //}
			}
           

        }
Exemple #3
0
        private void tsmiSaveAs_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.Filter = @"PNG (*.png)|*.png|JPEG (*.jpg)|*.jpg|Bitmap (*.bmp)|*.bmp|Encapsuled PostScript (*.eps)|*.eps|SVG (*.svg)|*.svg";
                saveFileDialog.FileName = txtQRCode.Text;
                saveFileDialog.DefaultExt = "png";

                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string filePath = saveFileDialog.FileName;

                    if (filePath.EndsWith("eps"))
                    {
                        // Initialize the EPS renderer
                        EncapsulatedPostScriptRenderer renderer = new EncapsulatedPostScriptRenderer(new FixedModuleSize(6, QuietZoneModules.Two), // Modules size is 6/72th inch (72 points = 1 inch)
                            new FormColor(Color.Black), new FormColor(Color.White));
                        BitMatrix matrix = qrMain.GetQrMatrix();
                        using (FileStream fs = new FileStream(filePath, FileMode.Create))
                        {
                            renderer.WriteToStream(matrix, fs);
                        }
                    }
                    else if (filePath.EndsWith("svg"))
                    {
                        // Initialize the EPS renderer
                        SVGRenderer renderer = new SVGRenderer(new FixedModuleSize(6, QuietZoneModules.Two), // Modules size is 6/72th inch (72 points = 1 inch)
                            new FormColor(Color.FromArgb(150, 200, 200, 210)), new FormColor(Color.FromArgb(200, 255, 155, 0)));
                        BitMatrix matrix = qrMain.GetQrMatrix();
                        using (FileStream fs = new FileStream(filePath, FileMode.Create))
                        {
                            renderer.WriteToStream(matrix, fs, false);
                        }
                    }
                    else
                    {
                        GraphicsRenderer gRender = new GraphicsRenderer(new FixedModuleSize(20, QuietZoneModules.Two));
                        BitMatrix matrix = qrMain.GetQrMatrix();
                        using (FileStream fs = new FileStream(filePath, FileMode.Create))
                        {
                            gRender.WriteToStream(matrix, ImageHelpers.GetImageFormat(filePath), fs);
                        }
                    }
                }
            }
        }
        private void CreateEPSImage(double imageSize, string fileName)
        {
            int pixelSize = (int)(imageSize * 72);

            EncapsulatedPostScriptRenderer epsRenderer = new EncapsulatedPostScriptRenderer(new FixedCodeSize(pixelSize, QuietZoneModules.Two),
                new EPSMediaColor(DarkColor), new EPSMediaColor(LightColor));

            using (FileStream stream = new FileStream(fileName, FileMode.Create))
            {
                epsRenderer.WriteToStream(QrMatrix, stream);
            }
        }
Exemple #5
0
        private void SaveQRCode(string folderName, string data, string orderType, int? quantity)
        {
            //SaveFileDialog saveFileDialog = new SaveFileDialog();
            //saveFileDialog.Filter = @"PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|Encapsuled PostScript (*.eps)|*.eps|SVG (*.svg)|*.svg";
            //saveFileDialog.FileName = Path.GetFileName(GetFileNameProposal(data));
            //saveFileDialog.DefaultExt = "png";

            //if (saveFileDialog.ShowDialog() != DialogResult.OK)
            //{
            //    return;
            //}

            fileName = folderName + "\\" + Path.GetFileName(GetFileNameProposal(data)) + ".png";

            if (fileName.EndsWith("eps"))
            {
                BitMatrix matrix = qrCodeGraphicControl.GetQrMatrix();

                // Initialize the EPS renderer
                var renderer = new EncapsulatedPostScriptRenderer(
                    new FixedModuleSize(6, QuietZoneModules.Two), // Modules size is 6/72th inch (72 points = 1 inch)
                    new FormColor(Color.Black), new FormColor(Color.White));

                using (var file = File.Open(fileName, FileMode.CreateNew))
                {
                    renderer.WriteToStream(matrix, file);
                }
            }
            else if (fileName.EndsWith("svg"))
            {
                BitMatrix matrix = qrCodeGraphicControl.GetQrMatrix();

                // Initialize the EPS renderer
                var renderer = new SVGRenderer(
                    new FixedModuleSize(6, QuietZoneModules.Two), // Modules size is 6/72th inch (72 points = 1 inch)
                    new FormColor(Color.FromArgb(150, 200, 200, 210)), new FormColor(Color.FromArgb(200, 255, 155, 0)));

                using (var file = File.OpenWrite(fileName))
                {
                    renderer.WriteToStream(matrix, file, false);
                }
            }
            else
            {
                GraphicsRenderer gRender = new GraphicsRenderer(new FixedModuleSize(4, QuietZoneModules.Four));
                BitMatrix matrix = qrCodeGraphicControl.GetQrMatrix();
                using (FileStream stream = new FileStream(fileName, FileMode.Create))
                {
                    gRender.WriteToStream(matrix, ImageFormat.Png, stream, new System.Drawing.Point(100, 100));
                }
            }
        }