/// <summary>
        /// Encode the content with desired parameters and save the generated Matrix
        /// </summary>
        /// <returns>True if the encoding succeeded, false if the content is empty or too large to fit in a QR code</returns>
        public bool TryEncode()
        {
            var encoder = new QrEncoder(Ecl);
            QrCode qr;
            if (!encoder.TryEncode(Content, out qr))
                return false;

            Matrix = qr.Matrix;
            return true;
        }
Пример #2
0
 public void CreateImageFile(BitMatrix matrix, string fileName, ImageFormat imageFormat)
 {
     Size size = Measure(matrix.Width);
     using (Bitmap bitmap = new Bitmap(size.Width, size.Height))
     using (Graphics graphics = Graphics.FromImage(bitmap))
     {
         Draw(graphics, matrix);
         bitmap.Save(fileName, imageFormat);
     }
 }
 public static void writeToFile(BitMatrix matrix, System.Drawing.Imaging.ImageFormat format, string file,int cm)
 {
     Bitmap bmap = toBitmap(matrix,matrix.Width,matrix.Height);
     //图像分辨率
     float dpiX = bmap.HorizontalResolution;
     float dpiY = bmap.VerticalResolution;
     double newW =cm * dpiX * 10/25.4;//cm转化为像素数
     double newH=cm*dpiY*10/25.4;
     bmap = toBitmap(matrix,(int)newW,(int)newH);
     bmap.Save(file, format);
 }
 public static Bitmap toBitmap(BitMatrix matrix, int width, int height)
 {
     // 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[x * matrix.Width / width, y * matrix.Height / height] != false ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF"));
     }
     }
     return bmap;
 }
Пример #5
0
        public void Draw(Graphics graphics, BitMatrix matrix, Point offset)
        {
            DrawQuietZone(graphics, matrix.Width, offset);
            Size paddingOffset = new Size(m_Padding, m_Padding) + new Size(offset.X, offset.Y);
            Size moduleSize = new Size(m_ModuleSize, m_ModuleSize);

            for (int j = 0; j < matrix.Width; j++)
            {
                for (int i = 0; i < matrix.Width; i++)
                {
                    Point moduleRelativePosition = new Point(i * m_ModuleSize, j * m_ModuleSize);
                    Rectangle moduleAbsoluteArea = new Rectangle(moduleRelativePosition + paddingOffset, moduleSize);
                    Brush bush = matrix[i, j] ? m_DarkBrush : m_LightBrush;
                    graphics.FillRectangle(bush, moduleAbsoluteArea);
                }
            }
        }
Пример #6
0
 internal QrCode(BitMatrix matrix)
 {
     this.Matrix = matrix;
     this.isContainMatrix = true;
 }
Пример #7
0
 public void Draw(Graphics graphics, BitMatrix matrix)
 {
     this.Draw(graphics, matrix, new Point(0, 0));
 }