QR코드 이미지 코드 생성 + 이미지 워터마크 추가 + 내보내기

8018 단어 QR코드
몇 가지 기본 정보에 따라 QR코드 이미지를 생성하고 QR코드 이미지에 그림의 물자국을 찍어서 내보내는 작은 프로젝트를 했다.
  
1. QR코드 생성
ZXing은 자바로 구현된 다양한 형식의 1D/2D 바코드 이미지 처리 라이브러리로 다른 언어와 연결된 포트를 포함한다.Zxing은 휴대전화에 내장된 카메라를 이용해 바코드 스캔 및 디코딩을 완료할 수 있다.이 프로젝트에서 실현할 수 있는 바코드 인코딩과 디코딩QR 인코딩, Data Matrix, UPC의 1D 바코드를 디코딩하는 것이 목표입니다.J2ME, J2SE, Android 등 다양한 플랫폼의 클라이언트를 제공합니다.QRcode를 디코딩하는 데 사용됩니다.본문은 zxing을 인용한다.dll, QR코드를 생성합니다.
참조 네임스페이스:
using com.google.zxing.qrcode;
using com.google.zxing;
using com.google.zxing.common;
using ByteMatrix = com.google.zxing.common.ByteMatrix;
using EAN13Writer = com.google.zxing.oned.EAN13Writer;
using EAN8Writer = com.google.zxing.oned.EAN8Writer;
using MultiFormatWriter = com.google.zxing.MultiFormatWriter;
using System.IO;
using System.Collections;

  
QR코드를 생성하려면 다음과 같이 하십시오.
private void btnGenerate_Click(object sender, EventArgs e)
        {
            ByteMatrix byteMatrix;
            string content = this.textBox1.Text;

            if (!string.IsNullOrEmpty(content))
            {
                byteMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 300, 300);
                bitmap = ToBitmap(byteMatrix);
            }

            this.pictureBox1.Image = bitmap;
            mapCreate = bitmap;
        }

        public static Bitmap ToBitmap(ByteMatrix matrix)
        {
            int width = matrix.Width;
            int height = matrix.Height;
            Bitmap bmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    bmap.SetPixel(x, y, matrix.get_Renamed(x, y) != -1 ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF"));
                }
            }
            return bmap;
        }

 
이미지 워터마크 추가:
//        
        private Bitmap ImageWatermark(Bitmap map, string waterpath)
        {
            Image waterimg = Image.FromFile(waterpath);

            //    
            Graphics g = Graphics.FromImage(map);

            //        
            ArrayList loca = new ArrayList();
            int x = 0;
            int y = 0;
            x = map.Width / 2 - waterimg.Width / 2;
            y = map.Height / 2 - waterimg.Height / 2;
            loca.Add(x);
            loca.Add(y);

            //g.DrawImage(waterimg, new Rectangle(int.Parse(loca[0].ToString()), int.Parse(loca[1].ToString()), waterimg.Width, waterimg.Height));
            g.DrawImage(waterimg, new Rectangle(int.Parse(loca[0].ToString()), int.Parse(loca[1].ToString()), 75, 75));

            return map;
        }

 
내보내기:
saveFileDialog 컨트롤을 먼저 추가합니다.
private void btnOut_Click(object sender, EventArgs e)
        {
            try
            {
                saveFileDialog1.ShowDialog();
                string fileName = saveFileDialog1.FileName;

                if (fileName != null)
                {
                    mapCreate.Save(fileName);//mapCreate bitmap     
                }
            }
            catch (Exception ex)
            {                
                throw;
            }
        }

좋은 웹페이지 즐겨찾기