コード例 #1
0
        public static void saveToFile(Bitmap img, string filepath)
        {
            CLogger.WriteLine("saving path is: " + filepath);
            using (Graphics gr = Graphics.FromImage(img))
            {
                gr.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                gr.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                img.Save(filepath);
                ///media/sf_Debug/img/export.png
                ///media/sf_debug/img/export.png
            }
        }
コード例 #2
0
        private void XMLConfigoader(string path)
        {
            if (!File.Exists(path))
            {
                CLogger.WriteLine("config file not found", true);
            }
            XmlDocument doc = new XmlDocument();

            doc.Load(path);

            foreach (XmlElement elem in doc.GetElementsByTagName("color"))
            {
                switch (elem.GetAttribute("type"))
                {
                case "emptyByte":
                    CCoder.ByteFalseColors.Add(Common.createColor(elem));
                    break;

                case "valueByte":
                    CCoder.ByteTrueColors.Add(Common.createColor(elem));
                    break;

                case "undefByte":
                    CCoder.ByteUndefColors.Add(Common.createColor(elem));
                    break;

                case "basicBackground":
                    CCoder.BackgroundColors.Add(Common.createColor(elem));
                    break;

                case "logoBackground":
                    CCoder.LogoCellColors.Add(Common.createColor(elem));
                    break;

                case "valueCellBorder":
                    CCoder.BorderColors.Add(Common.createColor(elem));
                    break;

                case "logoCellBorder":
                    CCoder.LogoBorderColors.Add(Common.createColor(elem));
                    break;
                }
            }
            IsConfigLoaded = true;
        }
コード例 #3
0
        public CApplicationController()
        {
            //для начала загружаем конфиг из файла
            try
            {
                XMLConfigoader(Path.GetDirectoryName(Application.ExecutablePath) + "/config.xml");
                CLogger.WriteLine("succes cfg load / parsing ");
                pointsMatrix = new CPointsMatrix(3000);

                if (!IsRunningOnMono())
                {
                    viewForm = new FimgView();
                    View     = viewForm as IViewInterfaces;
                    //свяжем интерфейс с контроллером
                    View.OnMsgGenerateQuery += RecieveMessage;
                }
            }
            catch (Exception e)
            {
                CLogger.WriteLine("Application Controller Ctor Fail: " + e.Message + ", " + e.InnerException, true);
                string searchPath = Path.GetDirectoryName(Application.ExecutablePath);
                if (File.Exists(searchPath + "/config.xml"))
                {
                    CLogger.WriteLine("Exist chek test pass succses", true);
                }
                else
                {
                    CLogger.WriteLine("Exist chek test faild", true);
                    CLogger.WriteLine("App current directory is: " + searchPath, true);
                    CLogger.WriteLine("Begin file scan in app directory:", true);
                    foreach (string name in Directory.GetFiles(searchPath))
                    {
                        CLogger.WriteLine(name, true);
                    }
                    CLogger.WriteLine("File scan end", true);
                }
            }
        }
コード例 #4
0
        public void RecieveMessage(SViewState viewState)
        {
            if (!IsConfigLoaded)
            {
                CLogger.WriteLine("config not loaded, app failed", true);
                return;
            }
            if (viewState.ReRand)
            {
                pointsMatrix.GenNoise(viewState.radius);
            }

            Bitmap bmp = CImgBuilder.GenBMPQRfromMatrix(this.pointsMatrix, viewState);

            if (View != null)
            {
                View.RecieveImg(bmp);
            }
            if (OnImageReady != null)
            {
                OnImageReady(bmp);
            }
        }
コード例 #5
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);
        }