Beispiel #1
0
        private static void DrawBytes(Graphics gr, CPointsMatrix matrix, SViewState viewState)
        {
            // Значащие биты
            List <CGexPoint> ValueBits = matrix.DrawData.Where(
                x => x.pointType == PointType.ByteTrue ||
                x.pointType == PointType.ByteFalse ||
                x.pointType == PointType.UndefinedByte).ToList();
            List <bool> databitsvalue = CCoder.EnCode(viewState.Message, ValueBits.Count);

            for (int i = 0; i < ValueBits.Count; i++)
            {
                if (ValueBits[i].Cell.Count > 2)
                {
                    ValueBits[i].pointType = databitsvalue[i] ? PointType.ByteTrue : PointType.ByteFalse;
                    if (viewState.FillCells)
                    {
                        gr.FillPolygon(new SolidBrush(CCoder.GetColorFor(matrix.DrawData[i].pointType)),
                                       Vector.ToSystemPointsF(ValueBits[i].Cell.ToArray()));
                    }
                    if (viewState.DrawCellBorder)
                    {
                        gr.DrawPolygon(new Pen(new SolidBrush(CCoder.GetColorFor(PointType.Border)), matrix.Height / (300f)),
                                       Vector.ToSystemPointsF(ValueBits[i].Cell.ToArray()));
                    }
                }
            }
        }
Beispiel #2
0
 private static void DrawBorderBackground(Graphics gr, CPointsMatrix matrix, SViewState viewState)
 {
     //Рисуем черный бордер
     Vector[] border = (from p in matrix.DrawData where p.pointType == PointType.Border select p.r).ToArray();
     if (viewState.DrawQRBorder)
     {
         gr.FillPolygon(new SolidBrush(CCoder.GetColorFor(PointType.Border)), Vector.ToSystemPointsF(border));
     }
 }
Beispiel #3
0
        private static void DrawLogo(Graphics gr, CPointsMatrix matrix, SViewState viewState)
        {
            // Логотип
            List <CGexPoint> logoBits = matrix.DrawData.Where(x => x.pointType == PointType.Logo).ToList();

            for (int i = 0; i < logoBits.Count; i++)
            {
                if (logoBits[i].Cell.Count > 2)
                {
                    if (viewState.FillCells)
                    {
                        gr.FillPolygon(
                            new SolidBrush(CCoder.GetColorFor(logoBits[i].pointType)),
                            Vector.ToSystemPointsF(logoBits[i].Cell.ToArray()));
                    }
                    if (viewState.DrawCellBorder)
                    {
                        gr.DrawPolygon(
                            new Pen(new SolidBrush(Color.Gray), matrix.Height / (350f)),
                            Vector.ToSystemPointsF(logoBits[i].Cell.ToArray()));
                    }
                }
            }
        }
Beispiel #4
0
        public static Bitmap GenBMPQRfromMatrix(CPointsMatrix matrix, SViewState viewState)
        {
            Bitmap bmp;

            if (matrix == null)
            {
                CLogger.WriteLine("FataL bug : matrix is null", true);
            }
            try
            {
                bmp = new Bitmap(matrix.Width, matrix.Height, PixelFormat.Format32bppArgb);
            }
            catch (Exception e)
            {
                CLogger.WriteLine("6.3 : " + e.Message, true);
                if (e.InnerException != null)
                {
                    CLogger.WriteLine("6.3 inner: " + e.InnerException.Message, true);
                }
                return(new Bitmap(1, 1));
            }
            using (Graphics gr = Graphics.FromImage(bmp))
            {
                gr.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                gr.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                gr.FillRectangle(new SolidBrush(CCoder.GetColorFor(PointType.Logo)), 0, 0, matrix.Width, matrix.Height);

                DrawBorderBackground(gr, matrix, viewState);
                DrawBytes(gr, matrix, viewState);
                DrawLogo(gr, matrix, viewState);
                DrawPoints(gr, matrix, viewState);
                //DrawLogoPoints(gr, matrix, viewState);

                //Отрисовка места под логотип
                //gr.FillPolygon(new SolidBrush(Color.WhiteSmoke), Vector.ToSystemPointsF(matrix.LogoBorderPoints.ToArray()));
#if DEBUG
                //DEBUG
                // вывод на экран окружения конкретной точки
                if (false)
                {
                    for (int i = 0; i < matrix.Points.Count; i++)
                    {
                        if (i != 5)
                        {
                            continue;
                        }
                        int[] points = matrix.sixNearest(i);
                        for (int jj = 0; jj < points.Length; jj++)
                        {
                            try
                            {
                                gr.DrawLine(new Pen(new SolidBrush(Color.Green)),
                                            (int)matrix.VectorAt(points[jj]).x + 2,
                                            (int)(int)matrix.VectorAt(points[jj]).y + 2,
                                            (int)matrix.VectorAt(points[jj]).x + 4,
                                            (int)(int)matrix.VectorAt(points[jj]).y + 4);
                                gr.DrawString(jj.ToString(),
                                              new Font("Sans Serif", 16f),
                                              new SolidBrush(Color.Green),
                                              (int)matrix.VectorAt(points[jj]).x + 5,
                                              (int)(int)matrix.VectorAt(points[jj]).y - 5);
                            }
                            catch (Exception e)
                            {
                                // do nothing
                            }
                        }
                    }
                }
                //END DEBUG
#endif
            }

            Bitmap fullimage = new Bitmap(Path.GetDirectoryName(Application.ExecutablePath) + @"/img/HexFrame.jpg");
            CLogger.WriteLine("Succes HexFrame loading");
            using (Graphics gr = Graphics.FromImage(fullimage))
            {
                gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                double resize     = (596.0 - 16 * 2.0) / (bmp.Width);
                Bitmap resizedBmp = new Bitmap(bmp, new Size((int)(bmp.Width * resize), (int)(bmp.Height * resize)));
                //CLogger.WriteLine("Succes qr resize to HexFrame");
                gr.DrawImage(resizedBmp, new Point(16, 16));
                CLogger.WriteLine("Succes drawing exist qr bitmap on hexframe");
            }
            return(fullimage);
        }