/// <summary>
        /// 主要作業方法
        /// </summary>
        public Image Operation()
        {
            Graphics g = Graphics.FromImage(image);
            _mask_pos_x = (image.Width / 2) + _Xoffset;
            SizeF steSize = new SizeF();
            for (int i = _FontMaxSize; i >= _FontMinSize; i--)
            {
                using (Font testFont = new Font(_FontFamily, i, FontStyle.Bold))
                {
                    steSize = g.MeasureString(_text, testFont);

                    if ((ushort)steSize.Width < (ushort)_Width || i == _FontMinSize)
                    {

                        using (SolidBrush semiTransBrush = new SolidBrush(_fontcolor))
                        {
                            StringFormat StrFormat = new StringFormat();
                            StrFormat.Alignment = StringAlignment.Center;
                            g.DrawString(_text, testFont, semiTransBrush, new PointF(_mask_pos_x, _mask_pos_y), StrFormat);
                            semiTransBrush.Dispose();
                        }
                        testFont.Dispose();
                        break;
                    }
                }
            }

            return image;
        }
Esempio n. 2
0
        /// <summary>
        /// Creating an image for a Captcha.
        /// </summary>
        /// <param name="captchaText">Text Captcha.</param>
        /// <returns></returns>
        public Bitmap Generate(string captchaText)
        {
            var bmp = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);
            using (Graphics graphics = Graphics.FromImage(bmp))
            {
                var rect = new Rectangle(0, 0, Width, Height);
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                using (var solidBrush = new SolidBrush(Color.White))
                {
                    graphics.FillRectangle(solidBrush, rect);
                }

                //Randomly choose the font name.
                var family = _fonts[new Random().Next(0, _fonts.Length)];
                var font = new Font(family, 30);

                using (var fontFormat = new StringFormat())
                {
                    //Format the font in the center.
                    fontFormat.Alignment = StringAlignment.Center;
                    fontFormat.LineAlignment = StringAlignment.Center;

                    var path = new GraphicsPath();
                    path.AddString(captchaText, font.FontFamily, (int)font.Style, font.Size, rect, fontFormat);
                    using (var solidBrush = new SolidBrush(Color.Blue))
                    {
                        graphics.FillPath(solidBrush, DeformPath(path));
                    }

                }
                font.Dispose();

            }
            return bmp;
        }
Esempio n. 3
0
 public void pictureBox1_Paint(object sender, PaintEventArgs e)
 {
     if (koord.Count != n)
         return;
     Point[] pnt = (Point[])koord.ToArray(typeof(Point));
     Font ft = new Font("Times New Roman", 16);
     Size sz = new Size(8, 8);
     int k = 0;
     control();
     e.Graphics.Clear(pictureBox1.BackColor);
     Graphics gr = e.Graphics;
     foreach (Point pt in koord)
     {
         e.Graphics.FillEllipse(Brushes.Gray, new Rectangle(pt, sz));
         e.Graphics.DrawString((k + 1).ToString(), ft, Brushes.Gray, pt.X - 20, pt.Y - 20);
         k++;
     }
     for (short i = 0; i < n; i++)
         for (short j = 0; j < n; j++)
             if (a[i, j] != 0)
             {
                 e.Graphics.DrawLine(Pens.Gray, pnt[i].X + 4, pnt[i].Y + 4, pnt[j].X + 4, pnt[j].Y + 4);
             }
     if (k >= n)
         button2.Enabled = true;
     else
         button2.Enabled = false;
     ft.Dispose();
 }
Esempio n. 4
0
        public override void PaintValue(PaintValueEventArgs e)
        {
            var ts = (TextStyle) e.Value;
            using (var b = new SolidBrush(ts.BackColor))
            {
                e.Graphics.FillRectangle(b, e.Bounds);
            }

            FontStyle fs = FontStyle.Regular;
            if (ts.Bold)
                fs |= FontStyle.Bold;
            if (ts.Italic)
                fs |= FontStyle.Italic;
            if (ts.Underline)
                fs |= FontStyle.Underline;

            var f = new Font("arial", 8f, fs);


            using (var b = new SolidBrush(ts.ForeColor))
            {
                e.Graphics.DrawString("abc", f, b, e.Bounds);
            }

            f.Dispose();
        }
Esempio n. 5
0
        public void Draw(Graphics g, bool enable)
        {
            Image back = PicLoader.Read("System", "ItemGrid.JPG");
            g.DrawImage(back, x+3, y+3, 32, 32);
            back.Dispose();

            if (itemPos >= 0)
            {
                Font font = new Font("Aril", 11*1.33f, FontStyle.Bold, GraphicsUnit.Pixel);
                if (enable)
                {
                    g.DrawImage(HItemBook.GetHItemImage(UserProfile.InfoBag.Items[itemPos].Type), x + 3, y + 3, 32, 32);
                }
                else
                {
                    Rectangle ret = new Rectangle(x + 3, y + 3, 32, 32);
                    g.DrawImage(HItemBook.GetHItemImage(UserProfile.InfoBag.Items[itemPos].Type), ret, 0, 0, 64, 64, GraphicsUnit.Pixel, HSImageAttributes.ToGray);
                }

                g.DrawString(UserProfile.InfoBag.Items[itemPos].Value.ToString(), font, Brushes.Black, x + 4, y + 4);
                g.DrawString(UserProfile.InfoBag.Items[itemPos].Value.ToString(), font, Brushes.White, x + 3, y + 3);

                if (percent>1)
                {
                    Brush brush = new SolidBrush(Color.FromArgb(200, Color.Black));
                    g.FillRectangle(brush, x, y, 35, 35*percent/100);
                    brush.Dispose();
                }

                font.Dispose();
            }
        }
Esempio n. 6
0
        private void TimeViewer_Paint(object sender, PaintEventArgs e)
        {
            LinearGradientBrush b1 = new LinearGradientBrush(new Rectangle(0, 0, Width, Height), Color.LightGreen, Color.Green, LinearGradientMode.Vertical);
            e.Graphics.FillRectangle(b1, 0, 0, round * Width, 30);
            b1.Dispose();

            Font font = new Font("Arial", 20*1.33f, FontStyle.Regular, GraphicsUnit.Pixel);
            e.Graphics.DrawString(string.Format("{0:00}:{1:00}", time / 4, (time % 4) * 15), font, Brushes.White, 22, 0);
            font.Dispose();

            if(isShow)
            {
                string url = string.Format("d{0}.JPG", daytime);
                Image img = PicLoader.Read("Weather", url);
                e.Graphics.DrawImage(img, 6, 35, 30, 30);
                img.Dispose();
                url = string.Format("w{0}.JPG", weather);
                img = PicLoader.Read("Weather", url);
                e.Graphics.DrawImage(img, 41, 35, 30, 30);
                img.Dispose();
                url = string.Format("s{0}.JPG", special);
                img = PicLoader.Read("Weather", url);
                e.Graphics.DrawImage(img, 76, 35, 30, 30);
                img.Dispose();
            }
        }
Esempio n. 7
0
		public override void Draw(Graphics gr) {
			// Calculation of begin and end points of edge. 
			double c = Math.Sqrt(Math.Pow(second.Position.X - first.Position.X, 2) + Math.Pow(second.Position.Y - first.Position.Y, 2));
			double sin = (second.Position.Y - first.Position.Y) / c;
			double cos = (second.Position.X - first.Position.X) / c;
			Point firstPoint = new Point(first.Position.X + (int)(cos * Vertex.r), first.Position.Y + (int)(sin * Vertex.r));
			Point secondPoint = new Point(second.Position.X - (int)(cos * Vertex.r), second.Position.Y - (int)(sin * Vertex.r));
			Pen edgePen = new Pen(Color.DarkBlue, 2);
			

			gr.DrawLine(edgePen, firstPoint, secondPoint);

			if (weight != 0) {
				string text = weight.ToString();
				Font textFont = new Font("Arial", 11);
				Brush textBrush = new SolidBrush(Color.Black);
				Brush textBackground = new SolidBrush(Color.White);
				Point textLocation = new Point((firstPoint.X + secondPoint.X) / 2, (firstPoint.Y + secondPoint.Y) / 2 - 6);

				SizeF textSize = new Size();
				textSize = gr.MeasureString(text, textFont);

				// Рисование линии между вершинам графа
				gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
				gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
				gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
				gr.DrawLine(edgePen, firstPoint, secondPoint);

				textBackground.Dispose();
				textBrush.Dispose();
				textFont.Dispose();
			}
			edgePen.Dispose();
		}
Esempio n. 8
0
        private void MessageBoxEx_Paint(object sender, PaintEventArgs e)
        {
            if (img != null)
            {
                e.Graphics.DrawImage(img, 38, 32, 100, 100);

                var deck = UserProfile.InfoCard.Decks[selectPage];
                for (int i = 0; i < deck.CardIds.Length; i++)
                {
                    int x = i%6;
                    int y = i/6;

                    var cardId = deck.CardIds[i];
                    e.Graphics.DrawImage(CardAssistant.GetCardImage(cardId,100,100),x*20+150,y*20+35,20,20);
                    var cardJob = CardConfigManager.GetCardConfig(cardId).JobId;
                    if (cardJob > 0 && cardJob != UserProfile.InfoBasic.Job)
                    {
                        var brush = new SolidBrush(Color.FromArgb(150, Color.Red));
                        e.Graphics.FillRectangle(brush, x * 20 + 150, y * 20 + 35, 20, 20);
                        brush.Dispose();
                        e.Graphics.DrawRectangle(Pens.Red, x * 20 + 150, y * 20 + 35, 20, 20);
                    }
                }
            }

            Font font = new Font("宋体", 9*1.33f, FontStyle.Regular, GraphicsUnit.Pixel);
            e.Graphics.DrawString(string.Format("地形:{0}", tile == -1 ? "默认" : ConfigDatas.ConfigData.GetTileConfig(tile).Cname), font, Brushes.White, 63, 117);
            font.Dispose();
        }
Esempio n. 9
0
 protected void Page_Load(object sender, EventArgs e)
 {
     Bitmap objBMP = new System.Drawing.Bitmap(60, 20);
     Graphics objGraphics = System.Drawing.Graphics.FromImage(objBMP);
     objGraphics.Clear(Color.Green);
     objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
     //' Configure font to use for text
     Font objFont = new Font("Arial", 8, FontStyle.Bold);
     string randomStr = "";
     int[] myIntArray = new int[5];
     int x;
     //That is to create the random # and add it to our string
     Random autoRand = new Random();
     for (x = 0; x < 5; x++)
     {
         myIntArray[x] = System.Convert.ToInt32(autoRand.Next(0, 9));
         randomStr += (myIntArray[x].ToString());
     }
     //This is to add the string to session cookie, to be compared later
     Session.Add("Captcha", randomStr);
     //' Write out the text
     objGraphics.DrawString(randomStr, objFont, Brushes.White, 3, 3);
     //' Set the content type and return the image
     Response.ContentType = "image/GIF";
     objBMP.Save(Response.OutputStream, ImageFormat.Gif);
     objFont.Dispose();
     objGraphics.Dispose();
     objBMP.Dispose();
 }
Esempio n. 10
0
		/// <summary>Adds a textual string to a bitmap image</summary>
		/// <param name="bitmap">The bitmap image to add the text to, or a null reference if a new image is to be created</param>
		/// <param name="txt">The text to overlay</param>
		/// <param name="fontname">The name of the font to use</param>
		/// <param name="fontsize">The size in points of the font</param>
		/// <param name="bgcolor">The background color to use (Only relevant if creating a new image)</param>
		/// <param name="fcolor">The font color to use</param>
		/// <param name="Padding">The padding to use, or alternatively the X,Y inset if overlaying text</param>
		public static Bitmap AddTextToBitmap(Bitmap bitmap, string txt, string fontname, int fontsize, Color bgcolor,Color fcolor, Vector2 Padding)
		{
			bool overlay = true;
			SizeF size;
			if (bitmap == null)
			{
				bitmap = new Bitmap(1024, 1024);
				overlay = false;
			}
			using (Graphics graphics = Graphics.FromImage(bitmap))
			{
				Font font = new Font(fontname, fontsize);
				size = graphics.MeasureString(txt, font);
				if (!overlay)
				{
					graphics.FillRectangle(new SolidBrush(bgcolor), 0, 0, size.Width + (int) Padding.X*2,size.Height + (int) Padding.Y*2);
				}
				graphics.DrawString(txt, font, new SolidBrush(fcolor), (int) Padding.X, (int) Padding.Y);
				graphics.Flush();
				font.Dispose();
				graphics.Dispose();
			}
			if (!overlay)
			{
				Rectangle cropArea = new Rectangle(0, 0, (int) size.Width + (int) Padding.X*2, (int) size.Height + (int) Padding.Y*2);
				return bitmap.Clone(cropArea, bitmap.PixelFormat);
			}
			return bitmap;
		}
Esempio n. 11
0
        public Bitmap generateBarcode(string data)
        {
            Bitmap b = new Bitmap(1, 1);
            Font font = new Font("Free 3 of 9", 60, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);

            Graphics g = Graphics.FromImage(b);

            SizeF dSize = g.MeasureString(data, font);
            b = new Bitmap(b, dSize.ToSize());
            g = Graphics.FromImage(b);

            g.Clear(Color.White);

            g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;

            g.DrawString(data, font, new SolidBrush(Color.Black), 0, 0);

            g.DrawString(data, new Font("Times new Romanow", 9, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point), new SolidBrush(Color.Black), 65, 58);

            g.Flush();
            font.Dispose();
            g.Dispose();

            return b;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            randomStr = "";
            Bitmap objBMP = new Bitmap(600, 200);
            Graphics objGraphics = System.Drawing.Graphics.FromImage(objBMP);
            objGraphics.Clear(Color.OrangeRed);
            objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
            Font objFont = new Font("Arial", 100, FontStyle.Bold);
         
            int x;
            Random autoRand = new Random();
            for (x = 0; x < 6; x++)
            {
               
                randomStr += (char)autoRand.Next(97, 122);
            }

            objGraphics.RotateTransform(-4);
            objGraphics.ScaleTransform(0.8F, 1.5F);
            objGraphics.DrawString(randomStr, objFont, Brushes.White,-10,-10);
            Response.ContentType = "image/GIF";
            objBMP.Save(Response.OutputStream, ImageFormat.Gif);
            objFont.Dispose();
            objGraphics.Dispose();
            objBMP.Dispose();
        }
Esempio n. 13
0
        /// <summary>
        /// Gera um Captcha dentro de um PageLoad em um webform vazio.
        /// Para usar, Crie um web form com o nome GerarCaptcha.aspx, e no codebehind chame a classe,
        /// Helpers.Arquivos.GerarCaptcha(int width, int height), e na pagina ou local onde quer que o captcha aparece,
        /// coloque um web server controle do tipo Image e atribua o ImageUrl="~/GerarCaptcha.aspx".
        /// EX: <asp:Image id="captchaImage" runat=server ImageUrl="~/GerarCaptcha.aspx" Height="50px" Width="150px" />
        /// Para usar o captcha no CodeBehind faca:
        /// 'Compare um campo TextBox com a Session["captcha"].ToString();
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public static void GerarCaptcha(int width, int height)
        {
            //Prepara os componentes de saida para desenho
            Bitmap bmp = new Bitmap(width, height);
            Graphics graph = Graphics.FromImage(bmp);

            //Limpa com cores locas..
            graph.Clear(Color.Aquamarine);
            graph.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
            //gera um random de letras e numeros
            string senhaCaptcha = "";
            Random rand = new Random();
            for (int x = 0; x < 6; x++)
                senhaCaptcha += (char)rand.Next(48, 122); //40 = zero 122 = z

            //grava na variavel de sessão
            HttpContext.Current.Session.Add("captcha", senhaCaptcha);

            //desenha na tela
            Font fonte = new Font("Calibri", 14, FontStyle.Italic);
            graph.DrawString(senhaCaptcha, fonte, Brushes.OliveDrab, 1, 1);

            //Manda pro rersponse
            HttpContext.Current.Response.ContentType = "image/gif";
            bmp.Save(HttpContext.Current.Response.OutputStream, ImageFormat.Gif);

            //Dispose
            graph.Dispose();
            fonte.Dispose();
            bmp.Dispose();
        }
Esempio n. 14
0
        private void DrawInitBitmap()
        {
            Bitmap house = new Bitmap("house.bmp");
            Bitmap car = new Bitmap("car.jpg");
            Bitmap man = new Bitmap("man.gif");
            Bitmap table = new Bitmap("table.bmp");

            // 실제 출력할 이미지
            m_bmpBackground = new Bitmap(500, 400);

            Font font = new Font("궁서체", 15);

            // 메모리 내부에서 이미지에 그리는 작업을 수행
            Graphics g = Graphics.FromImage(m_bmpBackground);
            g.FillRectangle(Brushes.White, new Rectangle(0, 0, 500, 400));

            g.DrawImage(house, new Rectangle(0,0,500,300));     // 궁전
            g.FillEllipse(Brushes.Red, new Rectangle(330, 40, 30, 30));
            g.DrawEllipse(Pens.Blue, new Rectangle(320, 30, 50, 50));
            g.DrawImage(car, 50, 310);    // 자동차 추가
            g.DrawImage(man, 30, 310);    // 사람 추가
            g.DrawImage(table, 150, 300); // 식탁 추가
            g.DrawString("더블 버퍼링 예제", font, Brushes.Black, 300, 320);

            g.Dispose();     // Bitmap 파일로 저장
            font.Dispose();
            car.Dispose();
            man.Dispose();
            table.Dispose();
        }
Esempio n. 15
0
        public override void Draw(Graphics g)
        {
            if (nid > 0)
            {
                int itemCount = UserProfile.Profile.InfoBag.GetItemCount(nid);
                bool isEnough = itemCount >= need;

                g.DrawImage(DataType.Items.HItemBook.GetHItemImage(nid), x, y, width, height);
                if (IsIn && isEnough)
                {
                    g.DrawImage(DataType.Items.HItemBook.GetHItemImage(nid), x+3, y+3, width-6, height-6);
                }
                if (!isEnough)
                {//灰色遮罩
                    Brush brush = new SolidBrush(Color.FromArgb(120, Color.Black));
                    g.FillRectangle(brush, x, y, width, height);
                    brush.Dispose();
                }

                Font fontsong = new Font("宋体", 7*1.33f, FontStyle.Regular, GraphicsUnit.Pixel);
                g.DrawString(string.Format("{0}/{1}", need, itemCount), fontsong, isEnough ? Brushes.White : Brushes.Red, x + 1, y + 18);
                fontsong.Dispose();
            }

            foreach (IRegionDecorator decorator in decorators)
            {
                decorator.Draw(g, x, y, width, height);
            }
        }
Esempio n. 16
0
		private void HatchBrushes_Paint(object sender, PaintEventArgs e)
		{
			
			int y = 20;
			int x = 20;

            Font font = new Font("Tahoma", 8);
			// Enumerate over all the styles.
			foreach (HatchStyle brushStyle in System.Enum.GetValues(typeof(HatchStyle)))
			{
				HatchBrush myBrush = new HatchBrush(brushStyle, Color.Blue, Color.LightYellow);

				// Fill a rectangle with the brush.
				e.Graphics.FillRectangle(myBrush, x, y, 40, 20);

				// Display the brush name.
				e.Graphics.DrawString(brushStyle.ToString(), font,
					Brushes.Black, 50 + x, y + 5);

				y += 30;
				if ((y + 30) > this.ClientSize.Height)
				{
					y = 20;
					x += 180;
				}
                myBrush.Dispose();
			}
            font.Dispose();
		}
Esempio n. 17
0
        /// <summary>
        /// 主要作業方法
        /// </summary>
        public Image Operation()
        {
            Graphics g = Graphics.FromImage(image);
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            StringFormat strFormat = new StringFormat();
            strFormat.Alignment = StringAlignment.Center;
            strFormat.LineAlignment = StringAlignment.Center;
            using (SolidBrush SB = new SolidBrush(_fontcolor))
            {
                using (Font str_Font = new Font(_FontFamily, _fontsize, FontStyle.Bold))
                {
                    g.SmoothingMode = SmoothingMode.HighQuality;
                    SizeF labelSize = g.MeasureString(_text, new Font(_FontFamily, _fontsize, FontStyle.Bold));
                    //g.TranslateTransform(0, labelSize.Width);
                    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    g.RotateTransform(_degree);
                    g.DrawString(_text, str_Font, new SolidBrush(_fontcolor), _mask_pos_x, _mask_pos_y);
                    str_Font.Dispose();
                }
                SB.Dispose();
            }
            return image;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Drawing.Bitmap objBmp = new System.Drawing.Bitmap(170, 45);
            System.Drawing.Graphics objGraphics = System.Drawing.Graphics.FromImage(objBmp);
            objGraphics.Clear(System.Drawing.Color.Gray);
            objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            System.Drawing.Font objFont = new System.Drawing.Font("Kristen ITC", 20, System.Drawing.FontStyle.Bold);
            string strRandom = "";
            string strRandomDisplay = "";
            string[] strArray = new string[36];
            strArray = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
            Random autoRand = new Random();

            int x;

            for (x = 0; x < 6; x++)
            {
                int i = Convert.ToInt32(autoRand.Next(0, 36));
                strRandom += strArray[i].ToString();
                strRandomDisplay += strArray[i].ToString() + " ";
            }

            Session.Add("strRandom", strRandom);
            objGraphics.DrawString(strRandomDisplay, objFont, System.Drawing.Brushes.Black, 3, 3);
            Response.ContentType = "image/GIF";
            objBmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
            objFont.Dispose();
            objGraphics.Dispose();
            objBmp.Dispose();
        }
Esempio n. 19
0
    public Bitmap GenerateBarcodeImage(string text, FontFamily fontFamily, int fontSizeInPoints)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("*");
        sb.Append(text);
        sb.Append("*");

        Bitmap bmp = new Bitmap(1, 1, PixelFormat.Format32bppArgb);

        Font font = new Font(fontFamily, fontSizeInPoints, FontStyle.Regular, GraphicsUnit.Point);

        Graphics graphics = Graphics.FromImage(bmp);

        SizeF textSize = graphics.MeasureString(sb.ToString(), font);

        bmp = new Bitmap(bmp, textSize.ToSize());

        graphics = Graphics.FromImage(bmp);
        graphics.Clear(Color.White);
        graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
        graphics.DrawString(sb.ToString(), font, new SolidBrush(Color.Black), 0, 0);
        graphics.Flush();

        font.Dispose();
        graphics.Dispose();

        return bmp;
    }
Esempio n. 20
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            // Calling the base class OnPaint
            base.OnPaint(pe);

            // diplay mask
            System.Drawing.Font drawFont = new System.Drawing.Font(FontFamily.GenericMonospace, 8.0F);
            System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
            System.Drawing.SolidBrush drawBrushGreen = new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen);

            bmpBackground.MakeTransparent(Color.Yellow);
            pe.Graphics.DrawImageUnscaled(bmpBackground, 0, 0);

            for (int i = 0; i < 8; i++)
            {
                pe.Graphics.DrawString(String.Format("{0:0}",RC_Values[i]), drawFont, drawBrush, 165,bar_pos[i]-13);
                int w = (int)((RC_Values[i] - 1000)/(double)(1000/120));
                if (w < 0) { w = 0; }
                if (w > 120) { w = 120; }

                pe.Graphics.FillRectangle(drawBrushGreen, 40, bar_pos[i]-10, w, 10);
            }

            drawFont.Dispose();
            drawBrush.Dispose();
            drawBrushGreen.Dispose();
        
        }
Esempio n. 21
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int x, y;
        string strValidation = null;
        rnd = new Random();
        Response.ContentType = "image/jpeg";
        Response.Clear();
        Response.BufferOutput = true;
        strValidation = GenerateString();
        Session["strValidation"] = strValidation;
        Font font = new Font("Arial", (float)rnd.Next(17, 20));

        Bitmap bitmap = new Bitmap(200, 50);
        Graphics gr = Graphics.FromImage(bitmap);
        gr.FillRectangle(Brushes.LightGreen, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
        gr.DrawString(strValidation, font, Brushes.Black, (float)rnd.Next(70), (float)rnd.Next(20));
           // gr.DrawLine(new Pen(Color.White), new Point(0, rnd.Next(50)), new Point(200, rnd.Next(50)));
           // gr.DrawLine(new Pen(Color.White), new Point(0, rnd.Next(50)), new Point(200, rnd.Next(50)));
           // gr.DrawLine(new Pen(Color.White), new Point(0, rnd.Next(50)), new Point(200, rnd.Next(50)));
        for (x = 0; x < bitmap.Width; x++)
            for (y = 0; y < bitmap.Height; y++)
                if (rnd.Next(4) == 1)
                    bitmap.SetPixel(x, y, Color.LightGreen);
        font.Dispose();
        gr.Dispose();
        bitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
        bitmap.Dispose();
    }
Esempio n. 22
0
 protected void Page_Load(object sender, EventArgs e)
 {
     var objBmp = new Bitmap(120, 30);
     var objGraphics = Graphics.FromImage(objBmp);
     objGraphics.Clear(Color.Green);
     objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
     //' Configure font to use for text
     var objFont = new Font("Arial", 21, FontStyle.Bold);
     string randomStr = "";
     var myIntArray = new int[5];
     int x;
     //That is to create the random # and add it to our string
     var autoRand = new Random();
     for (x = 0; x < 5; x++)
     {
         myIntArray[x] = Convert.ToInt32(autoRand.Next(0, 9));
         randomStr += (myIntArray[x].ToString(CultureInfo.InvariantCulture));
     }
     //This is to add the string to session cookie, to be compared later
     Session.Add("randomStr", randomStr);
     //' Write out the text
     objGraphics.DrawString(randomStr, objFont, Brushes.White, 3, 3);
     //' Set the content type and return the image
     Response.ContentType = "image/GIF";
     objBmp.Save(Response.OutputStream, ImageFormat.Gif);
     objFont.Dispose();
     objGraphics.Dispose();
     objBmp.Dispose();
 }
Esempio n. 23
0
 public void ProcessRequest(HttpContext context)
 {
     Bitmap objBMP = new Bitmap(200, 60);
     Graphics objGraphics = Graphics.FromImage(objBMP);
     objGraphics.Clear(Color.White);
     objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
     objGraphics.CompositingQuality = CompositingQuality.HighQuality;
     objGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
     //' Configure font to use for text
     Font objFont = new Font("Georgia", 26, FontStyle.Italic);
     //generate a random string for captcha
     string randomStr = GenerateRandomString(8);
     //This is to add the string to session cookie, to be compared later
     HttpContext.Current.Session.Add("captcha2", randomStr);
     //' Write out the text
     objGraphics.DrawString(randomStr, objFont, Brushes.Black, 3, 3);
     //' Set the content type and return the image
     context.Response.ContentType = "image/JPEG";
     //render image
     objBMP.Save(context.Response.OutputStream, ImageFormat.Jpeg);
     //dispose everything, we do not need them any more.
     objFont.Dispose();
     objGraphics.Dispose();
     objBMP.Dispose();
 }
Esempio n. 24
0
        public Bitmap AddCopyright(string file)
        {
            string msg = DateTime.Now.ToShortDateString();
            Bitmap bmp = new Bitmap(file);

            Graphics g = Graphics.FromImage(bmp);

            StringFormat strFmt = new StringFormat();
            strFmt.Alignment = StringAlignment.Center;

            SolidBrush btmForeColor = new SolidBrush(Color.White);
            SolidBrush btnBackColor = new SolidBrush(Color.Transparent);

            Font btmFont = new Font("Verdana", 7);
            SizeF textSize = new SizeF();

            textSize = g.MeasureString(msg, btmFont);

            float x = ((float)bmp.Width - textSize.Width - 3);
            float y = ((float)bmp.Height - textSize.Height - 3);
            float w = ((float)x + textSize.Width);
            float h = ((float)y + textSize.Height);

            RectangleF textArea = new RectangleF(x, y, w, h);
            g.FillRectangle(btnBackColor, textArea);

            g.DrawString(msg, btmFont, btmForeColor, textArea);
            btmForeColor.Dispose();
            btnBackColor.Dispose();
            btmFont.Dispose();
            g.Dispose();

            return bmp;
        }
Esempio n. 25
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            Pen contour = new Pen(Brushes.Black);
            Font writing = new Font(FontFamily.GenericSansSerif, 10);
            StringFormat formatWriting = new StringFormat();
            formatWriting.Alignment = StringAlignment.Far;
            SolidBrush writingBrush = new SolidBrush(Color.Black);
            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(new Bitmap(1, 1));
            int largeurTemp = (int)graphics.MeasureString(m_sTemp, writing).Width;

            if(m_temp < 0)
                pe.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(255, 4,130,255)), new Rectangle(0, 0, this.Size.Width, this.Size.Height));
            else
                pe.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(255, 224, 205, 14)), new Rectangle(0, 0, this.Size.Width, this.Size.Height));

            pe.Graphics.DrawLine(contour, 0, 0, this.Size.Width, 0);
            pe.Graphics.DrawLine(contour, 0, 0, 0, this.Size.Height);
            pe.Graphics.DrawLine(contour, this.Size.Width - 1, 0, this.Size.Width - 1, this.Size.Height);
            pe.Graphics.DrawLine(contour, 0, this.Size.Height - 1, this.Size.Width, this.Size.Height - 1);

            pe.Graphics.DrawString(m_sTemp, writing, writingBrush, new Rectangle(0, 1, largeurTemp + 2, 20), formatWriting);
            pe.Graphics.DrawString(m_sProfondeur, writing, writingBrush, new Rectangle(0, 20, largeurTemp, 20), formatWriting);

            pe.Graphics.DrawString(string.Format("{0: 0.00} °C", m_temp), writing, writingBrush, new Point(largeurTemp, 0));
            pe.Graphics.DrawString(string.Format("{0: 0.00} m", m_profondeur), writing, writingBrush, new Point(largeurTemp, 20));

            contour.Dispose();
            writing.Dispose();
            writingBrush.Dispose();
        }
Esempio n. 26
0
File: Form9.cs Progetto: kanke/cal
        private void monthCalendar1_DayRender(object sender, Pabo.Calendar.DayRenderEventArgs e)
        {
            Brush bgBrush =  new SolidBrush(Color.White);
            Brush dateBrush = new SolidBrush(Color.Black);
            Font dateFont = new Font("Microsoft Sans Serif",(float)8.25);
            StringFormat dateAlign = new StringFormat();

            dateAlign.Alignment = StringAlignment.Far;
            dateAlign.LineAlignment = StringAlignment.Near;

            Rectangle rect = new Rectangle(0,0,e.Width,e.Height);

            // Set OwnerDraw = true to override built in formatting...
            e.OwnerDraw = true;
            // ...then Draw the appearance of the date
            e.Graphics.FillRectangle(bgBrush,rect);
            e.Graphics.DrawString(e.Date.Day.ToString(),
                   dateFont,dateBrush,rect,dateAlign);

            // Clean up
            bgBrush.Dispose();
            dateBrush.Dispose();
            dateAlign.Dispose();
            dateFont.Dispose();
        }
Esempio n. 27
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (e.Index == -1 || e.Index >= this.Items.Count)
                return;

            if ((e.State == DrawItemState.Selected) || (e.State == DrawItemState.None))
            {
                e.DrawBackground();
            }
            try
            {

                Brush b = new SolidBrush(e.ForeColor);

                string fontname=this.Items[e.Index].ToString();
                Font   font=new Font(fontname,11);

                e.Graphics.DrawString(
                    fontname,
                    font,
                    b,
                    e.Bounds
                    );

                b.Dispose();
                font.Dispose();
                fontname=null;
            }
            catch{}

            base.OnDrawItem (e);
        }
Esempio n. 28
0
        private void GenerateMiniMap(int mapid, int wx, int wy)
        {
            Image allMap = PicLoader.Read("Map", "worldmap.JPG"); //生成世界地图
            Graphics g = Graphics.FromImage(allMap);
            Font font = new Font("微软雅黑", 18*1.33f, FontStyle.Bold, GraphicsUnit.Pixel);
            foreach (SceneMapIconConfig mapIconConfig in ConfigData.SceneMapIconDict.Values)
            {
                if (mapIconConfig.IconX < wx || mapIconConfig.IconX > wx + 300 || mapIconConfig.IconY < wy || mapIconConfig.IconY > wy + 300)
                    continue;
                string tname = ConfigData.GetSceneConfig(mapIconConfig.Id).Name;
                g.DrawString(tname, font, Brushes.Black, mapIconConfig.IconX + 2, mapIconConfig.IconY + 21);
                g.DrawString(tname, font, mapIconConfig.Id == mapid ? Brushes.Lime : Brushes.White, mapIconConfig.IconX, mapIconConfig.IconY + 20);
            }
            font.Dispose();
            g.Dispose();

            if (miniMap != null)
            {
                miniMap.Dispose();
            }
            miniMap = new Bitmap(150, 150); //绘制小地图
            g = Graphics.FromImage(miniMap);
            Rectangle destRect = new Rectangle(0, 0, 150, 150);
            g.DrawImage(allMap, destRect, wx, wy, 300, 300, GraphicsUnit.Pixel);
            g.Dispose();
            allMap.Dispose();
        }
Esempio n. 29
0
        public override void Draw(Graphics g, int target)
        {
            Image head = PicLoader.Read("NPC", string.Format("{0}.PNG", Figue));
            int ty = Y + 50;
            int ty2 = ty;
            if (target == Id)
            {
                g.DrawImage(head, X - 5, ty - 5, Width*5/4, Width * 5 / 4);
                ty2 -= 2;
            }
            else
            {
                g.DrawImage(head, X, ty, Width, Width);
            }

            head.Dispose();

            Font font = new Font("΢ÈíÑźÚ", 12*1.33f, FontStyle.Bold, GraphicsUnit.Pixel);
            g.DrawString(Name, font, Brushes.Black, X + 3, Y + Height + 30);
            g.DrawString(Name, font, Brushes.White, X, Y + Height + 27);
            font.Dispose();

            if (taskFinishs.Count > 0)
            {
                Image img = PicLoader.Read("System", "MarkTaskEnd.PNG");
                g.DrawImage(img, X + 15, ty2 - 35, 21, 30);
                img.Dispose();
            }
            else if (taskAvails.Count > 0)
            {
                Image img = PicLoader.Read("System", "MarkTaskBegin.PNG");
                g.DrawImage(img, X + 15, ty2 - 35, 24, 30);
                img.Dispose();
            }
        }
Esempio n. 30
0
    internal System.Drawing.Font get_drawing_font()
    {
        if (internal_font == null || check_font_dirty())
        {
            System.Drawing.FontFamily ff;
            try
            {
                ff = new System.Drawing.FontFamily(name, private_fonts);
            }
            catch (Exception e)
            {
                ff = new System.Drawing.FontFamily(name);
            }
            System.Drawing.FontStyle style = System.Drawing.FontStyle.Regular;
            if (bold && ff.IsStyleAvailable(System.Drawing.FontStyle.Bold))
            {
                style = System.Drawing.FontStyle.Bold;
            }
            if (italic && ff.IsStyleAvailable(System.Drawing.FontStyle.Italic))
            {
                style = System.Drawing.FontStyle.Italic;
            }
            if (bold && italic && ff.IsStyleAvailable(System.Drawing.FontStyle.Bold) && ff.IsStyleAvailable(System.Drawing.FontStyle.Italic))
            {
                style = System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic;
            }

            if (internal_font != null)
            {
                internal_font.Dispose();
            }
            internal_font = new System.Drawing.Font(ff, size - 10, style, System.Drawing.GraphicsUnit.Pixel);
        }
        return(internal_font);
    }
Esempio n. 31
0
        private void CalendarForm_Paint(object sender, PaintEventArgs e)
        {
            BorderPainter.Draw(e.Graphics, "", Width, Height);

            Font font = new Font("黑体", 12*1.33f, FontStyle.Bold, GraphicsUnit.Pixel);
            e.Graphics.DrawString("日 历", font, Brushes.White, Width / 2 - 40, 8);
            font.Dispose();

            if (!showImage)
                return;

            //if (nowSeason == UserProfile.Profile.time.Season)
            //{
            //    int day = UserProfile.Profile.time.Day;
            //    for (int i = 0; i < 28; i++)
            //    {
            //        if (day > i)
            //        {
            //            e.Graphics.FillRectangle(Brushes.DimGray, 30 + 70 * (i%7), 45 + 70 * (i/7), 70,70);
            //        }
            //        else if (day == i)
            //        {
            //            e.Graphics.FillRectangle(Brushes.DarkRed, 30 + 70 * (i % 7), 45 + 70 * (i / 7), 70, 70);
            //        }
            //    }
            //}
            Pen pen = new Pen(Color.White, 2);
            for (int i = 0; i < 5; i++)
            {
                e.Graphics.DrawLine(pen, 30, 45 + 70 * i, 520, 45 + 70 * i);
            }
            for (int i = 0; i < 8; i++)
            {
                e.Graphics.DrawLine(pen, 30 + 70 * i, 45, 30 + 70 * i, 325);
            }
            pen.Dispose();
            font = new Font("黑体", 12*1.33f, FontStyle.Bold, GraphicsUnit.Pixel);
            Font font2 = new Font("宋体", 9*1.33f, FontStyle.Regular, GraphicsUnit.Pixel);
            for (int i = 0; i < 28; i++)
            {
                e.Graphics.DrawString((i + 1).ToString().PadLeft(2), font, Brushes.White, 70 * (i%7)+63, 70 * (i/7)+53);
                int date = nowSeason*28 + i;
                int maid = TournamentBook.GetDayApplyId(date);
                int mmid = TournamentBook.GetDayMatchId(date);

                if (maid != 0)
                {
                    e.Graphics.DrawImage(HSIcons.GetIconsByEName("oth2"), 70 * (i % 7) + 37, 70 * (i / 7) + 50,24,24);
                    e.Graphics.DrawString(ConfigDatas.ConfigData.GetTournamentConfig(maid).Name, font2, Brushes.White, 70 * (i % 7) + 33, 70 * (i / 7) + 95);
                }
                else if (mmid != 0)
                {
                    e.Graphics.DrawImage(HSIcons.GetIconsByEName("oth1"), 70 * (i % 7) + 37, 70 * (i / 7) + 50, 24, 24);
                    e.Graphics.DrawString(ConfigDatas.ConfigData.GetTournamentConfig(mmid).Name, font2, Brushes.White, 70 * (i % 7) + 33, 70 * (i / 7) + 95);
                }
            }
            font.Dispose();
            font2.Dispose();
        }
Esempio n. 32
0
        protected override void Dispose(bool disposing)
        {
            if (mDisposed)
            {
                return;
            }

            if (disposing)
            {
                mFont?.Dispose();
                mGraphics.Dispose();
                mImage.Dispose();
            }

            mDisposed = true;

            base.Dispose(disposing);
        }
Esempio n. 33
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            StringFormat fontAlignMent = new StringFormat();
            //String strText = this.Text;
            Rectangle  textRect  = GetTextRect();//获得图形矩形
            Font       textFont  = new System.Drawing.Font(this.Font.Name, this.Font.Size, this.Font.Style);
            SolidBrush fontBrush = new System.Drawing.SolidBrush(this.ForeColor);

            fontAlignMent.Alignment     = StringAlignment.Center;//设置字体显示时候的对齐方式
            fontAlignMent.LineAlignment = StringAlignment.Center;
            String text = this.HeadName;
            Pen    pen  = new Pen(Color.White);

            pe.Graphics.DrawRectangle(pen, textRect);
            pe.Graphics.DrawString(text, textFont, fontBrush, textRect, fontAlignMent);

            fontBrush.Dispose();
            fontAlignMent.Dispose();
            textFont.Dispose();
            fontBrush.Dispose();
            base.OnPaint(pe);
            base.OnPaint(pe);
        }
Esempio n. 34
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds,
                                      int rowIndex, DataGridViewElementStates cellState,
                                      object value, object formattedValue, string errorText,
                                      DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle
                                      advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

            Font      font            = new System.Drawing.Font("Calibri", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Color     color           = (Color)value;
            Brush     backgroundBrush = new SolidBrush(color);
            Brush     textBrush       = new SolidBrush(color.GetBrightness() <= 0.5f ? Color.White : Color.Black);
            Rectangle cellRectangle   = new Rectangle(cellBounds.X, cellBounds.Y, cellBounds.Width - 1, cellBounds.Height - 1);
            string    text            = "***";
            SizeF     size            = graphics.MeasureString(text, font);

            graphics.FillRectangle(backgroundBrush, cellRectangle);
            graphics.DrawString(text, font, textBrush, cellBounds.X + cellBounds.Width / 2 - size.Width / 2, cellBounds.Y + cellBounds.Height / 2 - size.Height / 2);

            backgroundBrush.Dispose();
            textBrush.Dispose();
            font.Dispose();
        }
Esempio n. 35
0
        //*********************************************************************************************************************************************
        //
        // Method Name: DrawPauseScreen
        //
        // Description:
        //  TODO: Add description.
        //
        // Arguments:
        //  theGraphics - TODO: Add description.
        //
        // Return:
        //  N/A
        //
        //*********************************************************************************************************************************************
        private void DrawPauseScreen(Graphics theGraphics)
        {
            // Setup the text for the scores and timers.
            Font textFont = new System.Drawing.Font(BreakoutConstants.TEXT_FAMILY_NAME,
                                                    BreakoutConstants.PAUSE_SCREEN_TEXT_SIZE);
            SolidBrush   textColor  = new SolidBrush(Color.Black);
            StringFormat textFormat = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            // Draw the right player score to be centered on the right half (third quarter horizontal, half vertical) of the screen.
            theGraphics.DrawString(BreakoutConstants.PAUSE_STRING,
                                   textFont,
                                   textColor,
                                   mBreakoutGame.Form.Size.Width / BreakoutConstants.HALF,
                                   mBreakoutGame.Form.Size.Height / BreakoutConstants.HALF,
                                   textFormat);

            // Clean up allocated memory.
            textFont.Dispose();
        }
    public void AutoImage(string strCompanyName)
    {
        Int16 swidth = Convert.ToInt16(strCompanyName.Length * 13);

        System.Drawing.Bitmap   objBMP      = new System.Drawing.Bitmap(swidth, 30);
        System.Drawing.Graphics objGraphics = System.Drawing.Graphics.FromImage(objBMP);
        objGraphics.Clear(System.Drawing.Color.White);
        objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
        //' Configure font to use for text
        System.Drawing.Font objFont = new System.Drawing.Font("Arial", 15, System.Drawing.FontStyle.Bold);

        string randomStr = strCompanyName;

        int[] myIntArray = new int[6];
        int   x;

        //That is to create the random # and add it to our string
        //Random autoRand = new Random();
        //for (x = 0; x < 6; x++)
        //{
        //    myIntArray[x] = System.Convert.ToInt32(autoRand.Next(0, 9));
        //    randomStr += (myIntArray[x].ToString());
        //}
        //This is to add the string to session cookie, to be compared later


        //' Write out the text
        objGraphics.DrawString(strCompanyName, objFont, System.Drawing.Brushes.Black, 3, 3);

        //' Set the content type and return the image
        //Response.ContentType = "image/GIF";
        File.Delete(HttpContext.Current.Server.MapPath("~\\provider\\LogoImages\\Default.jpg"));
        objBMP.Save(HttpContext.Current.Server.MapPath("~\\provider\\LogoImages\\Default.jpg"), objBMP.RawFormat);
        objFont.Dispose();
        objGraphics.Dispose();
        objBMP.Dispose();
    }
Esempio n. 37
0
        //*********************************************************************************************************************************************
        //
        // Method Name: Draw
        //
        // Description:
        //  TODO: Add description.
        //
        // Arguments:
        //  theGraphics - TODO: Add description.
        //
        // Return:
        //  N/A
        //
        //*********************************************************************************************************************************************
        public override void Draw(Graphics theGraphics)
        {
            // Setup the color of the ball the indicates the selector .
            SolidBrush ballColor = new SolidBrush(Color.Blue);

            // Setup the text for the scores and timers.
            Font textFont = new System.Drawing.Font(BreakoutConstants.TEXT_FAMILY_NAME,
                                                    BreakoutConstants.START_SCREEN_TEXT_SIZE);
            SolidBrush   textColor  = new SolidBrush(Color.Black);
            StringFormat textFormat = new StringFormat()
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            // Draw the ball, which indicates the selector.
            theGraphics.FillEllipse(ballColor,
                                    new RectangleF((mBreakoutGame.Form.Size.Width / BreakoutConstants.HALF) - 150,
                                                   240 + ((int)mSelection * (int)((float)BreakoutConstants.START_SCREEN_TEXT_SIZE * 1.5F)),
                                                   BreakoutConstants.BALL_WIDTH_AND_HEIGHT,
                                                   BreakoutConstants.BALL_WIDTH_AND_HEIGHT));


            // Draw the right player score to be centered on the right half (third quarter horizontal, half vertical) of the screen.
            theGraphics.DrawString("New Game\nExit",
                                   textFont,
                                   textColor,
                                   mBreakoutGame.Form.Size.Width / BreakoutConstants.HALF,
                                   mBreakoutGame.Form.Size.Height / BreakoutConstants.HALF,
                                   textFormat);

            // Clean up allocated memory.
            ballColor.Dispose();
            textFont.Dispose();
            textColor.Dispose();
            textFormat.Dispose();
        }
Esempio n. 38
0
        protected override void Dispose(bool Disposing)
        {
            if (Disposing)
            {
                AutoSizeChanged = null;
                _AutoSize       = false;

                DrawFormatChanged = null;
                _DrawFormat       = DrawTextFormat.None;

                FontChanged = null;

                if (_Font != null)
                {
                    _Font.Dispose();
                }
                _Font = null;

                if (DXFont != null && !DXFont.Disposed)
                {
                    DXFont.Dispose();
                }
                DXFont = null;

                OutLineChanged = null;
                _OutLine       = false;

                OutLineColorChanged = null;
                _OutLineColor       = Color.Empty;

                TextChanged = null;
                Text        = null;
            }

            base.Dispose(Disposing);
        }
Esempio n. 39
0
        /// <summary>
        /// Paints the text items, which are part of CloudCollection.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TagCloudControl_Paint(object sender, PaintEventArgs e)
        {
            Graphics formGraphics = e.Graphics;

            formGraphics.Clear(this.m_ControlBackColor);

            int i = 0;
            ICollection <string> text = CloudCollection.Keys;

            foreach (CloudItem ci in CloudCollection.Values)
            {
                if (ci.Touched)
                {
                    FontStyle fs = FontStyle.Regular;
                    if (m_Underline)
                    {
                        fs |= FontStyle.Underline;
                    }
                    //Font drawFont = new System.Drawing.Font(ci.Design.drawFont.FontFamily, 12, fs);
                    Font drawFont = new System.Drawing.Font(ci.Design.drawFont.FontFamily, ci.Design.drawFont.Size, fs);
                    formGraphics.DrawString(text.ElementAt <string>(i++), drawFont, ci.Design.drawBrush, ci.Position.X, ci.Position.Y);
                    drawFont.Dispose();
                }
                else
                {
                    formGraphics.DrawString(text.ElementAt <string>(i++), ci.Design.drawFont, ci.Design.drawBrush, ci.Position.X, ci.Position.Y);
                }
                if (m_Frame)
                {
                    Pen p = new Pen(ci.Design.drawBrush, 1);
                    formGraphics.DrawRectangle(p, ci.Position);
                    p.Dispose();
                }
            }
            formGraphics.Dispose();
        }
Esempio n. 40
0
        public void DrawString(BufferedGraphics myBuffer, float x, float y, float y2, double d, string drawString)
        {
            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(0x44, 0x44, 0x88));
            myBuffer.Graphics.FillRectangle(myBrush,
                                            new Rectangle(10, (int)y,
                                                          (int)(d / series.Select(linq => linq.Value.Val).Max() * this.Width),
                                                          (int)y2));

            System.Drawing.Font         drawFont   = new System.Drawing.Font("Arial", 16);
            System.Drawing.SolidBrush   drawBrush  = new System.Drawing.SolidBrush(System.Drawing.Color.White);
            System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
            //myBuffer.Graphics.DrawString(d + " " + drawString, drawFont, drawBrush, x, y, drawFormat);
            myBuffer.Graphics.DrawString(drawString + ": " + d, drawFont, drawBrush, x, y, drawFormat);

            drawFont.Dispose();
            drawBrush.Dispose();


            //this.Invalidate();

            myBrush.Dispose();

            //Form1_Paint(null, null);
        }
        protected override void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    MakeCurrent();
                    if (labelTexture != null)
                    {
                        labelTexture.Dispose();
                        labelTexture = null;
                    }

                    if (labelFont != null)
                    {
                        labelFont.Dispose();
                        labelFont = null;
                    }
                    disposed = true;
                }
            }

            base.Dispose(disposing);
        }
Esempio n. 42
0
        private void writeMe(string drawString, int fon_t, float x, float y, Boolean det_a, int dl)
        {
            if (det_a)
            {
                deta[dl].fon_t = fon_t;
                deta[dl].x     = (float)x;
                deta[dl].yy    = (float)y;
            }
            try
            {
                // Console.WriteLine("dd :" + drawString+": dd"+ fon_t+"gg"+x+"fff"+y+"jjjj  "+dl);
                System.Drawing.Graphics formGraphics = formGraphics = this.CreateGraphics();

                System.Drawing.Font drawFont = new System.Drawing.Font("Arial", fon_t);

                System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
                formGraphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
                drawFont.Dispose();


                formGraphics.Dispose();
            }
            catch (Exception g) { }
        }
        private static Bitmap CreateLabel(String data)
        {
            data = data.ToUpper();

            Bitmap docTypeLabel = new Bitmap(1, 1);

            System.Drawing.Font timesNR = new System.Drawing.Font("Times New Roman", 80, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);

            Graphics graphics = Graphics.FromImage(docTypeLabel);

            SizeF dataSize = new SizeF();

            SizeF dataSize_text = graphics.MeasureString(data, timesNR);

            dataSize.Width = dataSize_text.Width;

            dataSize.Height = dataSize_text.Height;

            docTypeLabel = new Bitmap(docTypeLabel, dataSize.ToSize());

            graphics = Graphics.FromImage(docTypeLabel);

            graphics.Clear(Color.White);

            graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;

            graphics.DrawString(data, timesNR, new SolidBrush(Color.Black), ((dataSize.Width / 2f) - (dataSize_text.Width / 2f)), 0);

            graphics.Flush();

            timesNR.Dispose();

            graphics.Dispose();

            return(docTypeLabel);
        }
Esempio n. 44
0
            // Creates the bitmap image
            private void GenerateImage()
            {
                // Create a new 32-bit bitmap image
                Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb);

                // Create a graphics object for drawing
                Graphics g = Graphics.FromImage(bitmap);

                g.SmoothingMode = SmoothingMode.AntiAlias;
                var rect = new System.Drawing.Rectangle(0, 0, this.width, this.height);

                // Fill in the background
                HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, System.Drawing.Color.LightGray, System.Drawing.Color.White);

                g.FillRectangle(hatchBrush, rect);

                // Set up the text font
                SizeF size;
                float fontSize = rect.Height + 1;

                System.Drawing.Font font;

                // Adjust the font size until the text fits within the image.
                do
                {
                    fontSize--;
                    font = new System.Drawing.Font(this.familyName, fontSize, FontStyle.Bold);
                    size = g.MeasureString(this.text, font);
                } while (size.Width > rect.Width);

                // Set up the text format
                StringFormat format = new StringFormat();

                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;

                // Create a path using the text and warp it randomly
                GraphicsPath path = new GraphicsPath();

                path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format);
                float v = 4F;

                PointF[] points =
                {
                    new PointF(this.random.Next(rect.Width) / v,              this.random.Next(rect.Height) / v),
                    new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
                    new PointF(this.random.Next(rect.Width) / v,              rect.Height - this.random.Next(rect.Height) / v),
                    new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v)
                };
                Matrix matrix = new Matrix();

                matrix.Translate(0F, 0F);
                path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);

                // Draw the text
                hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, System.Drawing.Color.LightGray, System.Drawing.Color.DarkGray);
                g.FillPath(hatchBrush, path);

                // Add some random noise
                int m = Math.Max(rect.Width, rect.Height);

                for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
                {
                    int x = this.random.Next(rect.Width);
                    int y = this.random.Next(rect.Height);
                    int w = this.random.Next(m / 50);
                    int h = this.random.Next(m / 50);
                    g.FillEllipse(hatchBrush, x, y, w, h);
                }

                // Clean up
                font.Dispose();
                hatchBrush.Dispose();
                g.Dispose();

                // Set the image
                this.image = bitmap;
            }
Esempio n. 45
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            // Calling the base class OnPaint
            base.OnPaint(pe);

            System.Drawing.Font       drawFont        = new System.Drawing.Font(FontFamily.GenericMonospace, 8.0F);
            System.Drawing.SolidBrush drawBrushOrange = new System.Drawing.SolidBrush(System.Drawing.Color.Orange);
            System.Drawing.SolidBrush drawBrushWhite  = new System.Drawing.SolidBrush(System.Drawing.Color.White);
            System.Drawing.SolidBrush drawBrushDim    = new System.Drawing.SolidBrush(System.Drawing.Color.Gray);

            bmpRedOff.MakeTransparent(Color.Yellow);
            bmpRedOn.MakeTransparent(Color.Yellow);
            bmpGreenOff.MakeTransparent(Color.Yellow);
            bmpGreenOn.MakeTransparent(Color.Yellow);

            if (indicator_color == 0)
            {
                if (status)
                {
                    pe.Graphics.DrawImageUnscaled(bmpGreenOn, 0, 0);
                }
                else
                {
                    pe.Graphics.DrawImageUnscaled(bmpGreenOff, 0, 0);
                }
            }
            else
            {
                if (status)
                {
                    pe.Graphics.DrawImageUnscaled(bmpRedOn, 0, 0);
                }
                else
                {
                    pe.Graphics.DrawImageUnscaled(bmpRedOff, 0, 0);
                }
            }
            SizeF stringSize = new SizeF();

            stringSize = pe.Graphics.MeasureString(Text, drawFont);
            if (status)
            {
                if (indicator_color == 0)
                {
                    pe.Graphics.DrawString(Text, drawFont, drawBrushWhite, 1 + (48 - stringSize.Width) / 2, (15 - stringSize.Height) / 2);
                }
                else
                {
                    pe.Graphics.DrawString(Text, drawFont, drawBrushOrange, 1 + (48 - stringSize.Width) / 2, (15 - stringSize.Height) / 2);
                }
            }
            else
            {
                pe.Graphics.DrawString(Text, drawFont, drawBrushDim, 1 + (48 - stringSize.Width) / 2, (15 - stringSize.Height) / 2);
            }

            //Dispose objects
            drawFont.Dispose();
            drawBrushDim.Dispose();
            drawBrushOrange.Dispose();
            drawBrushWhite.Dispose();
        }
Esempio n. 46
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            // Calling the base class OnPaint
            base.OnPaint(pe);

            bmpHeadingWheel.MakeTransparent(Color.Yellow);
            bmpLeftLedGreen.MakeTransparent(Color.Yellow);
            bmpLeftLedRed.MakeTransparent(Color.Yellow);
            bmpRightLedGreen.MakeTransparent(Color.Yellow);
            bmpRightLedRed.MakeTransparent(Color.Yellow);
            bmpSatGreen.MakeTransparent(Color.Yellow);
            bmpSatRed.MakeTransparent(Color.Yellow);
            bmpBackGround.MakeTransparent(Color.Yellow);


            // diplay mask
            Pen maskPen = new Pen(this.BackColor, 30);

            pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpBackGround.Width, bmpBackGround.Height);

            // display background
            pe.Graphics.DrawImageUnscaled(bmpBackGround, 0, 0);

            //Leds
            if (GPS_home)
            {
                pe.Graphics.DrawImageUnscaled(bmpLeftLedGreen, 0, 0);
            }
            else
            {
                pe.Graphics.DrawImageUnscaled(bmpLeftLedRed, 0, 0);
            }
            if (GPS_pkt)
            {
                pe.Graphics.DrawImageUnscaled(bmpRightLedGreen, 0, 0);
            }
            else
            {
                pe.Graphics.DrawImageUnscaled(bmpRightLedRed, 0, 0);
            }


            Bitmap   bmp = new Bitmap(136, 136);
            Graphics gfx = Graphics.FromImage(bmp);

            gfx.TranslateTransform(68f, 68f);
            gfx.RotateTransform(Heading);
            gfx.TranslateTransform(-68f, -68f);
            gfx.DrawImageUnscaled(bmpHeadingWheel, 0, 0);
            pe.Graphics.DrawImageUnscaled(bmp, 7, 7);

            // display Sat

            if (GPS_fix)
            {
                pe.Graphics.DrawImageUnscaled(bmpSatGreen, 0, 0);
            }
            else
            {
                pe.Graphics.DrawImageUnscaled(bmpSatRed, 0, 0);
            }


            //And add text
            System.Drawing.Font       drawFont    = new System.Drawing.Font(FontFamily.GenericMonospace, 8.0F);
            System.Drawing.Font       drawSatFont = new System.Drawing.Font("Arial", 10.0F);
            System.Drawing.SolidBrush drawBrush   = new System.Drawing.SolidBrush(System.Drawing.Color.White);
            pe.Graphics.DrawString(String.Format("{0:0000 m}", Distance), drawFont, drawBrush, 55, 100);
            pe.Graphics.DrawString(String.Format("{0:000°}", Heading), drawFont, drawBrush, 62, 40);
            pe.Graphics.DrawString(String.Format("{0:0}", Numsat), drawSatFont, drawBrush, 89, 64);

            //Dispose temp objects
            maskPen.Dispose();
            gfx.Dispose();
            bmp.Dispose();
            drawFont.Dispose();
            drawSatFont.Dispose();
            drawBrush.Dispose();
        }
Esempio n. 47
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            // Calling the base class OnPaint
            base.OnPaint(pe);

            // diplay mask
            Pen drawPen = new Pen(Color.White, 1);
            Pen maskPen = new Pen(this.BackColor, 5);

            System.Drawing.Font       drawFont       = new System.Drawing.Font(FontFamily.GenericMonospace, 8.0F);
            System.Drawing.SolidBrush drawBrush      = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
            System.Drawing.SolidBrush drawBrushGreen = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(123, 194, 205));
            System.Drawing.SolidBrush drawBrushBlue  = new System.Drawing.SolidBrush(System.Drawing.Color.LightBlue);


            switch (CopterTypeToDraw)
            {
            case CopterType.QuadX:
                bmpQuadX.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpQuadX.Width, bmpQuadX.Height);
                pe.Graphics.DrawImageUnscaled(bmpQuadX, 0, 0, bmpQuadX.Width, bmpQuadX.Height);
                for (i = 0; i < 4; i++)
                {
                    int h = (int)((motorvals[i] - 900) * (float)(coord_quadX[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_quadX[i, 0], coord_quadX[i, 1] - h, 8, h);
                    pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_quadX[i, 0] + 12, coord_quadX[i, 1] - 10);
                }
                break;

            case CopterType.QuadP:
                bmpQuadP.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpQuadP.Width, bmpQuadP.Height);
                pe.Graphics.DrawImageUnscaled(bmpQuadP, 0, 0, bmpQuadP.Width, bmpQuadP.Height);
                for (i = 0; i < 4; i++)
                {
                    int h = (int)((motorvals[i] - 900) * (float)(coord_quadP[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_quadP[i, 0], coord_quadP[i, 1] - h, 8, h);
                    pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_quadP[i, 0] + 12, coord_quadP[i, 1] - 10);
                }
                break;

            case CopterType.Tri:
                bmpTri.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpTri.Width, bmpTri.Height);
                pe.Graphics.DrawImageUnscaled(bmpTri, 0, 0, bmpTri.Width, bmpTri.Height);
                for (i = 0; i < 3; i++)
                {
                    int h = (int)((motorvals[i] - 900) * (float)(coord_tri[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_tri[i, 0], coord_tri[i, 1] - h, 8, h);
                    pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_tri[i, 0] + 12, coord_tri[i, 1] - 10);
                }
                l = (int)((servovals[5] - 900) * (float)(coord_tri[3, 2] / 1200.0f));
                pe.Graphics.FillRectangle(drawBrushGreen, coord_tri[3, 0], coord_tri[3, 1] - 10, l, 8);
                pe.Graphics.DrawString(String.Format("{0:0}", servovals[5]), drawFont, drawBrush, coord_tri[3, 0] - 32, coord_tri[3, 1] - 13);
                break;

            case CopterType.Gimbal:
                bmpGimbal.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpGimbal.Width, bmpGimbal.Height);
                pe.Graphics.DrawImageUnscaled(bmpGimbal, 0, 0, bmpGimbal.Width, bmpGimbal.Height);
                for (i = 0; i < 2; i++)
                {
                    l = (int)((servovals[i + 1] - 900) * (float)(coord_gimbal[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_gimbal[i, 0], coord_gimbal[i, 1] - 10, l, 10);
                    pe.Graphics.DrawString(String.Format("{0:0}", servovals[i + 1]), drawFont, drawBrush, coord_gimbal[i, 0], coord_gimbal[i, 1]);
                }
                break;

            case CopterType.Y6:
                bmpY6.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpY6.Width, bmpY6.Height);
                pe.Graphics.DrawImageUnscaled(bmpY6, 0, 0, bmpY6.Width, bmpY6.Height);
                for (i = 0; i < 6; i++)
                {
                    int h = (int)((motorvals[i] - 900) * (float)(coord_y6[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_y6[i, 0], coord_y6[i, 1] - h, 9, h);
                    if (i < 3)
                    {
                        pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_y6[i, 0] + 9, coord_y6[i, 1] - 73);
                    }
                    else
                    {
                        pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_y6[i, 0] + 9, coord_y6[i, 1] - 11);
                    }
                }
                break;

            case CopterType.Y4:
                bmpY4.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpY4.Width, bmpY4.Height);
                pe.Graphics.DrawImageUnscaled(bmpY4, 0, 0, bmpY4.Width, bmpY4.Height);
                for (i = 0; i < 4; i++)
                {
                    int h = (int)((motorvals[i] - 900) * (float)(coord_y4[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_y4[i, 0], coord_y4[i, 1] - h, 10, h);
                    pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_y4[i, 0] + 12, coord_y4[i, 1] - 10);
                }
                break;

            case CopterType.BI:
                bmpBi.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpBi.Width, bmpBi.Height);
                pe.Graphics.DrawImageUnscaled(bmpBi, 0, 0, bmpBi.Width, bmpBi.Height);
                for (i = 0; i < 2; i++)
                {
                    int h = (int)((motorvals[i] - 900) * (float)(coord_bi[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_bi[i, 0], coord_bi[i, 1] - h, 10, h);
                    pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_bi[i, 0] + 12, coord_bi[i, 1] - 10);
                }
                for (i = 0; i < 2; i++)
                {
                    l = (int)((servovals[i] - 900) * (float)(coord_bi[2 + i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_bi[2 + i, 0], coord_bi[2 + i, 1] - 10, l, 10);
                    pe.Graphics.DrawString(String.Format("{0:0}", servovals[i]), drawFont, drawBrush, coord_bi[2 + i, 0], coord_bi[2 + i, 1]);  //??? is servo 0 in new gui also?
                }
                break;

            case CopterType.Hex6:
                bmpHex6.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpHex6.Width, bmpHex6.Height);
                pe.Graphics.DrawImageUnscaled(bmpHex6, 0, 0, bmpHex6.Width, bmpHex6.Height);
                for (i = 0; i < 6; i++)
                {
                    int h = (int)((motorvals[i] - 900) * (float)(coord_hex6[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_hex6[i, 0], coord_hex6[i, 1] - h, 10, h);
                    pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_hex6[i, 0] + 9, coord_hex6[i, 1] - 12);
                }
                break;

            case CopterType.Hex6X:
                bmpHex6X.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpHex6X.Width, bmpHex6X.Height);
                pe.Graphics.DrawImageUnscaled(bmpHex6X, 0, 0, bmpHex6X.Width, bmpHex6X.Height);
                for (i = 0; i < 6; i++)
                {
                    int h = (int)((motorvals[i] - 900) * (float)(coord_hex6x[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_hex6x[i, 0], coord_hex6x[i, 1] - h, 8, h);
                    if (i > 3)
                    {
                        pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_hex6x[i, 0] - 12, coord_hex6x[i, 1] + 10);
                    }
                    else
                    {
                        pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_hex6x[i, 0] - 12, coord_hex6x[i, 1] + 10);
                    }
                }
                break;

            case CopterType.FlyWing:
                bmpFw.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpFw.Width, bmpFw.Height);
                pe.Graphics.DrawImageUnscaled(bmpFw, 0, 0, bmpFw.Width, bmpFw.Height);
                int bar = (int)((motorvals[0] - 900) * (float)(coord_wing[0, 2] / 1200.0f));
                pe.Graphics.FillRectangle(drawBrushGreen, coord_wing[0, 0], coord_wing[0, 1] - bar, 10, bar);
                pe.Graphics.DrawString(String.Format("{0:0}", motorvals[0]), drawFont, drawBrush, coord_wing[0, 0] + 12, coord_wing[0, 1] - 10);
                for (i = 1; i < 3; i++)
                {
                    int h = (int)((servovals[i] - 900) * (float)(coord_wing[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_wing[i, 0], coord_wing[i, 1] - h, 10, h);
                    pe.Graphics.DrawString(String.Format("{0:0}", servovals[i]), drawFont, drawBrush, coord_wing[i, 0] + 12, coord_wing[i, 1] - 10);
                }
                break;

            case CopterType.Octo8Coax:
                bmpOcto8c.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpOcto8c.Width, bmpOcto8c.Height);
                pe.Graphics.DrawImageUnscaled(bmpOcto8c, 0, 0, bmpOcto8c.Width, bmpOcto8c.Height);
                for (i = 0; i < 8; i++)
                {
                    int h = (int)((motorvals[i] - 900) * (float)(coord_octo8c[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_octo8c[i, 0], coord_octo8c[i, 1] - h, 10, h);
                    pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_octo8c[i, 0] - 12, coord_octo8c[i, 1]);
                }
                break;

            case CopterType.Octo8P:
                bmpOcto8p.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpOcto8p.Width, bmpOcto8p.Height);
                pe.Graphics.DrawImageUnscaled(bmpOcto8p, 0, 0, bmpOcto8p.Width, bmpOcto8p.Height);
                for (i = 0; i < 8; i++)
                {
                    int h = (int)((motorvals[i] - 900) * (float)(coord_octo8p[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_octo8p[i, 0], coord_octo8p[i, 1] - h, 10, h);
                    pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_octo8p[i, 0] - 12, coord_octo8p[i, 1] + 8);
                }
                break;

            case CopterType.Octo8X:
                bmpOcto8x.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpOcto8x.Width, bmpOcto8x.Height);
                pe.Graphics.DrawImageUnscaled(bmpOcto8x, 0, 0, bmpOcto8x.Width, bmpOcto8x.Height);
                for (i = 0; i < 8; i++)
                {
                    int h = (int)((motorvals[i] - 900) * (float)(coord_octo8x[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_octo8x[i, 0], coord_octo8x[i, 1] - h, 10, h);
                    pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_octo8x[i, 0] - 12, coord_octo8x[i, 1] + 8);
                }
                break;

            case CopterType.Vtail:
                bmpVtail.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpVtail.Width, bmpVtail.Height);
                pe.Graphics.DrawImageUnscaled(bmpVtail, 0, 0, bmpVtail.Width, bmpVtail.Height);
                for (i = 0; i < 4; i++)
                {
                    int h = (int)((motorvals[i] - 900) * (float)(coord_y4[i, 2] / 1200.0f));
                    pe.Graphics.FillRectangle(drawBrushGreen, coord_y4[i, 0], coord_y4[i, 1] - h, 10, h);
                    pe.Graphics.DrawString(String.Format("{0:0}", motorvals[i]), drawFont, drawBrush, coord_y4[i, 0] + 12, coord_y4[i, 1] - 10);
                }
                break;

            case CopterType.Airplane:
                bmpAirplane.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpAirplane.Width, bmpAirplane.Height);
                pe.Graphics.DrawImageUnscaled(bmpAirplane, 0, 0, bmpAirplane.Width, bmpAirplane.Height);

                hval = (int)((servovals[3] - 900) * (float)(coord_airplane[0, 2] / 1200.0f));              //Wing1
                pe.Graphics.FillRectangle(drawBrushGreen, coord_airplane[0, 0], coord_airplane[0, 1] - hval, 10, hval);
                pe.Graphics.DrawString(String.Format("{0:0}", servovals[3]), drawFont, drawBrush, coord_airplane[0, 0] + 12, coord_airplane[0, 1] - 10);

                hval = (int)((servovals[4] - 900) * (float)(coord_airplane[1, 2] / 1200.0f));              //Wing2
                pe.Graphics.FillRectangle(drawBrushGreen, coord_airplane[1, 0], coord_airplane[1, 1] - hval, 10, hval);
                pe.Graphics.DrawString(String.Format("{0:0}", servovals[4]), drawFont, drawBrush, coord_airplane[1, 0] + 12, coord_airplane[1, 1] - 10);

                hval = (int)((servovals[5] - 900) * (float)(coord_airplane[2, 2] / 1200.0f));              //Rudder
                pe.Graphics.FillRectangle(drawBrushGreen, coord_airplane[2, 0], coord_airplane[2, 1] - 10, hval, 10);
                pe.Graphics.DrawString(String.Format("{0:0}", servovals[5]), drawFont, drawBrush, coord_airplane[2, 0], coord_airplane[2, 1] + 10);

                hval = (int)((servovals[6] - 900) * (float)(coord_airplane[3, 2] / 1200.0f));              //Elevator
                pe.Graphics.FillRectangle(drawBrushGreen, coord_airplane[3, 0], coord_airplane[3, 1] - hval, 10, hval);
                pe.Graphics.DrawString(String.Format("{0:0}", servovals[6]), drawFont, drawBrush, coord_airplane[3, 0] + 12, coord_airplane[3, 1] - 12);

                hval = (int)((servovals[7] - 900) * (float)(coord_airplane[4, 2] / 1200.0f));              //Throttle
                pe.Graphics.FillRectangle(drawBrushGreen, coord_airplane[4, 0], coord_airplane[4, 1] - hval, 10, hval);
                pe.Graphics.DrawString(String.Format("{0:0}", servovals[7]), drawFont, drawBrush, coord_airplane[4, 0] + 12, coord_airplane[4, 1] - 10);
                break;

            case CopterType.Heli120:
                bmpHeli120.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpHeli120.Width, bmpHeli120.Height);
                pe.Graphics.DrawImageUnscaled(bmpHeli120, 0, 0, bmpHeli120.Width, bmpHeli120.Height);

                for (i = 0; i <= 4; i++)
                {
                    hval = (int)((servovals[3 + i] - 900) * (float)(coord_heli120[i, 2] / 1200.0f));
                    if (i == 2)
                    {
                        pe.Graphics.FillRectangle(drawBrushGreen, coord_heli120[i, 0], coord_heli120[i, 1] - 10, hval, 10);
                    }
                    else
                    {
                        pe.Graphics.FillRectangle(drawBrushGreen, coord_heli120[i, 0], coord_heli120[i, 1] - hval, 10, hval);
                    }
                    pe.Graphics.DrawString(String.Format("{0:0}", servovals[3 + i]), drawFont, drawBrush, coord_heli120[i, 0], coord_heli120[i, 1] + 10);
                }
                break;

            case CopterType.Heli90:
                bmpHeli90.MakeTransparent(Color.Yellow);
                pe.Graphics.DrawRectangle(maskPen, 0, 0, bmpHeli90.Width, bmpHeli90.Height);
                pe.Graphics.DrawImageUnscaled(bmpHeli90, 0, 0, bmpHeli90.Width, bmpHeli90.Height);

                for (i = 0; i <= 4; i++)
                {
                    hval = (int)((servovals[3 + i] - 900) * (float)(coord_heli90[i, 2] / 1200.0f));
                    if (i == 2)
                    {
                        pe.Graphics.FillRectangle(drawBrushGreen, coord_heli90[i, 0], coord_heli90[i, 1] - 10, hval, 10);
                    }
                    else
                    {
                        pe.Graphics.FillRectangle(drawBrushGreen, coord_heli90[i, 0], coord_heli90[i, 1] - hval, 10, hval);
                    }
                    pe.Graphics.DrawString(String.Format("{0:0}", servovals[3 + i]), drawFont, drawBrush, coord_heli90[i, 0], coord_heli120[i, 1] + 10);
                }
                break;
            }

            //Disposing graph objects
            drawPen.Dispose();
            maskPen.Dispose();
            drawFont.Dispose();
            drawBrush.Dispose();
            drawBrushGreen.Dispose();
            drawBrushBlue.Dispose();
        }
Esempio n. 48
0
    public ArrayList batUpload()
    {
        //string shopName = "";
        //string strSQL = "select shopName from T_Shop_User where shopid=(select ProviderInfo from T_Goods_info where goodsid='" + goodsId + "' and Datafrom='ShopSeller');select memberName from T_member_info where memberId=(select ProviderInfo from T_Goods_info where goodsid='" + goodsId + "' and Datafrom='PersonSeller');";

        //DataSet ds = adohelper.ExecuteSqlDataset(strSQL);
        //if (ds == null || ds.Tables.Count < 2)
        //    return null;

        //if (ds.Tables[0].Rows.Count > 0)
        //    shopName = ds.Tables[0].Rows[0][0].ToString();
        //else
        //    shopName = ds.Tables[1].Rows[0][0].ToString();

        ArrayList list      = new ArrayList();
        AdoHelper adohelper = AdoHelper.CreateHelper(StarTech.Util.AppConfig.DBInstance);
        //搜集表单中的file元素
        HttpFileCollection files = Request.Files;

        //遍历file元素
        for (int i = 0; i < files.Count; i++)
        {
            HttpPostedFile       postedFile = files[i];
            HtmlInputCheckBox [] ck         = { Checkbox1, Checkbox2, Checkbox3, Checkbox4 };
            if (postedFile.FileName != "")
            {
                //文件大小
                int fileSize = postedFile.ContentLength / 1024;
                if (fileSize == 0)
                {
                    fileSize = 1;
                }

                //提取文件名
                string oldFileName = Path.GetFileName(postedFile.FileName);

                //提取文件扩展名
                string oldFileExt = Path.GetExtension(oldFileName);

                //重命名文件
                string newFileName = Guid.NewGuid().ToString() + oldFileExt;

                //设置保存目录
                string webDirectory  = "/upload/goodsadmin/" + DateTime.Now.ToString("yyyyMMdd") + "/";
                string saveDirectory = Server.MapPath(webDirectory);
                if (!Directory.Exists(saveDirectory))
                {
                    Directory.CreateDirectory(saveDirectory);
                }

                //设置保存路径
                string savePath = saveDirectory + newFileName;
                //保存
                postedFile.SaveAs(savePath);

                string savePath2    = savePath;
                string newFileName2 = newFileName;
                if (ck[i].Checked)
                {
                    //System.Drawing.Image nowImg = System.Drawing.Image.FromFile(savePath);
                    System.Drawing.Bitmap nowImg2 = new System.Drawing.Bitmap(savePath);
                    System.Drawing.Bitmap nowImg  = new System.Drawing.Bitmap(nowImg2.Width, nowImg2.Height);

                    float x = nowImg.Width - 50;
                    float y = nowImg.Height - 30;

                    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(nowImg);
                    g.DrawImage(nowImg2, 0, 0);
                    System.Drawing.Font  f = new System.Drawing.Font("华文彩云", 12);
                    System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
                    g.DrawString("才通天下微信公号", f, b, x, y);
                    f = new System.Drawing.Font("华文琥珀", 12);
                    b = new System.Drawing.SolidBrush(System.Drawing.Color.White);
                    g.DrawString("才通天下微信公号·", f, b, x, y);
                    f.Dispose();
                    b.Dispose();
                    g.Dispose();
                    nowImg2.Dispose();
                    //savePath2 = webDirectory + newFileName.Replace(oldFileExt, "" + oldFileExt);
                    string nGuid = Guid.NewGuid().ToString();
                    nGuid        = nGuid.Replace(nGuid[new Random().Next(1, 9)], nGuid[new Random().Next(10, 15)]);
                    newFileName2 = nGuid + oldFileExt;
                    savePath2    = webDirectory + newFileName2;
                    MemoryStream ms = new MemoryStream();
                    nowImg.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    byte[] imgData = ms.ToArray();
                    File.Delete(savePath);
                    FileStream fs = new FileStream(savePath, FileMode.Create, FileAccess.ReadWrite);
                    if (fs != null)
                    {
                        fs.Write(imgData, 0, imgData.Length);
                        fs.Close();
                    }
                    nowImg.Dispose();
                }



                //缩略图
                MakeSmallPic(Server.MapPath(webDirectory + newFileName), Server.MapPath(webDirectory + newFileName.Replace(oldFileExt, ".jpg")));
                string goodsSmallPic = webDirectory + newFileName.Replace(oldFileExt, "" + oldFileExt);

                list.Add(oldFileName + "|" + fileSize + "|" + goodsSmallPic);
            }
        }
        return(list);
    }
Esempio n. 49
0
        public bool MakeImage(ref Image image, ref Image imageOriginal, float zoom = 0, List <LabelItem> labels = null)
        {
            try
            {
                if (zoom == 0)
                {
                    zoom = this.Zoom;
                }
                if (labels == null)
                {
                    labels = this.labels;
                }

                //若无东西 就清空image
                if (imageOriginal == null)
                {
                    if (image != null)
                    {
                        image.Dispose();
                        image = null;
                    }
                    return(false);
                }

                //图像来自外部 清除内部缓存
                if (imageOriginal != this.imageOriginal)
                {
                    if (imageZoomed != null)
                    {
                        imageZoomed.Dispose();
                        imageZoomed = null;
                    }
                }

                //判断有没有必要生成
                if (imageZoomed != null && Math.Abs(this.Zoom - zoom) < 0.001f && !EnableMakeImage)
                {
                    return(false);
                }

                //缩图
                if ((imageZoomed == null) ||
                    !(Math.Abs(imageZoomedZoomValue - zoom) < 0.001))
                {
                    imageZoomedZoomValue = zoom;

                    if (imageZoomed != null)
                    {
                        imageZoomed.Dispose();
                    }

                    imageZoomed = new Bitmap(imageOriginal, (int)(imageOriginal.Size.Width * zoom), (int)(imageOriginal.Size.Height * zoom));
                }

                //释放缓存
                if (image != null)
                {
                    image.Dispose();
                }

                //贴上标签
                image = new Bitmap(imageZoomed);
                Graphics tmp = Graphics.FromImage(image);
                if (!hideLabel && labels != null)
                {
                    float labelFontSize = LabelSideLength(image) / 1.6f;

                    for (int i = 0; i < labels.Count; i++)
                    {
                        RectangleF rect   = getLabelRectangle(labels[i].X_percent, labels[i].Y_percent, image);
                        Font       myFont = new System.Drawing.Font(new FontFamily("Arial"), labelFontSize, FontStyle.Bold);

                        Brush myBrushRed   = new SolidBrush(colorList[labels[i].Category - 1]);
                        Brush myBrushWhite = new SolidBrush(Color.White);
                        Pen   mySidePen    = new Pen(myBrushRed, LabelSideLength(image) / 10f);

                        StringFormat sf = new StringFormat();
                        sf.Alignment     = StringAlignment.Center;
                        sf.LineAlignment = StringAlignment.Center;

                        //实体字
                        tmp.DrawString((i + 1).ToString(), myFont, myBrushRed, rect.X + rect.Width / 2, rect.Y + rect.Height / 2, sf);

                        //外框
                        //tmp.DrawRectangle(mySidePen, rect.X, rect.Y, rect.Width, rect.Height);

                        //显示Group
                        if (AlwaysShowGroup || showGroup)
                        {
                            Font       groupFont = new System.Drawing.Font(new FontFamily("simsun"), labelFontSize / 1.5f, FontStyle.Bold);
                            float      myWidth   = labelFontSize * 10;
                            RectangleF groupRect = new RectangleF(
                                rect.X + rect.Width / 2 - myWidth / 2,
                                rect.Y - labelFontSize,
                                myWidth,
                                rect.Height);

                            tmp.DrawString(groupString[labels[i].Category - 1], groupFont, myBrushRed, groupRect, sf);

                            groupFont.Dispose();
                        }

                        myFont.Dispose();
                        myBrushRed.Dispose();
                        myBrushWhite.Dispose();
                        mySidePen.Dispose();
                        sf.Dispose();
                    }
                }

                Refresh();
                tmp.Dispose();
                return(true);
            }
            catch { return(false); }
        }
Esempio n. 50
0
        public static void DrawTimeLine(object sender1, PaintEventArgs e)
        {
            /*
             * 5 минут = 30п
             * 1 час по 5 минут = 12 раз по 30 п = 360 п
             * 24 часа по 5 минут = 24 по 360 п = 8640п +- отступ по 5 пикселей верх низ
             * подпись справа формат хх:хх
             * отступ справа 20
             */
            Panel sender = sender1 as Panel;

            sender.Height = 8660;
            int      x           = 0;
            int      xw          = sender.Width;
            int      y1          = 5;
            int      y2          = 8650;
            Pen      grad        = new Pen(Color.Black);
            Graphics MyFormPaint = sender.CreateGraphics();

            MyFormPaint.DrawLine(grad, x, y1, x, y2);

            System.Drawing.Font       drawFont  = new System.Drawing.Font("Arial", 8);
            System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
            int hours = 19;
            int mins  = 0;

            for (int i = 0; i <= 288; i++)
            {
                int small   = 10;
                int big     = 20;
                int kurrent = small;

                if (i == 0 || i - 12 == 0 || i % 12 == 0)
                {
                    kurrent = big;
                }
                int y = i * 30 + 5;

                string drawString = String.Format("{0:d2}:{1:d2}", hours, mins);
                mins += 5;
                if (mins == 60)
                {
                    mins = 0;
                    hours++;
                    if (hours == 24)
                    {
                        hours = 0;
                    }
                }



                MyFormPaint.DrawLine(grad, x, y, x + kurrent, y);
                StringFormat drawFormat = new StringFormat();
                MyFormPaint.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
            }
            drawFont.Dispose();
            drawBrush.Dispose();
            grad.Dispose();
            MyFormPaint.Dispose();
            foreach (var a in sender.Parent.Controls)
            {
                if (a is Button == true)
                {
                    (a as Button).Width = sender.Parent.Width - 40;
                }
            }
        }
Esempio n. 51
0
        private void FreeResources()
        {
            #region Text Dispose
            if (_d3dMouseFixtionFont != null)
            {
                _d3dMouseFixtionFont.Dispose();
                _d3dMouseFixtionFont = null;
            }
            if (_d3dGazeFixtionFont != null)
            {
                _d3dGazeFixtionFont.Dispose();
                _d3dGazeFixtionFont = null;
            }

            if (_gdiMouseFixtionFont != null)
            {
                _gdiMouseFixtionFont.Dispose();
                _gdiMouseFixtionFont = null;
            }
            if (_gdiGazeFixtionFont != null)
            {
                _gdiGazeFixtionFont.Dispose();
                _gdiGazeFixtionFont = null;
            }
            #endregion

            #region Texture Dispose
            if (_mouseCursorTex != null)
            {
                _mouseCursorTex.Dispose();
                _mouseCursorTex = null;
            }
            if (_gazeCursorTex != null)
            {
                _gazeCursorTex.Dispose();
                _gazeCursorTex = null;
            }
            #endregion

            #region Line Dispose
            if (_d3dMouseTrackLine != null)
            {
                _d3dMouseTrackLine.Dispose();
                _d3dMouseTrackLine = null;
            }

            if (_d3dMouseCursorCircleLine != null)
            {
                _d3dMouseCursorCircleLine.Dispose();
                _d3dMouseCursorCircleLine = null;
            }

            if (_d3dMouseFixationLine != null)
            {
                _d3dMouseFixationLine.Dispose();
                _d3dMouseFixationLine = null;
            }

            if (_d3dMouseScanpathLine != null)
            {
                _d3dMouseScanpathLine.Dispose();
                _d3dMouseScanpathLine = null;
            }

            if (_d3dGazeTrackLine != null)
            {
                _d3dGazeTrackLine.Dispose();
                _d3dGazeTrackLine = null;
            }

            if (_d3dGazeCursorCircleLine != null)
            {
                _d3dGazeCursorCircleLine.Dispose();
                _d3dGazeCursorCircleLine = null;
            }

            if (_d3dGazeFixationLine != null)
            {
                _d3dGazeFixationLine.Dispose();
                _d3dGazeFixationLine = null;
            }

            if (_d3dGazeScanpathLine != null)
            {
                _d3dGazeScanpathLine.Dispose();
                _d3dGazeScanpathLine = null;
            }
            #endregion

            if (sprite != null)
            {
                sprite.Dispose();
                sprite = null;
            }

            if (device != null)
            {
                device.Dispose();
                device = null;
            }
        }
Esempio n. 52
0
        /// <summary>
        /// Create barcode from the text.s
        /// </summary>
        /// <param name="txt">
        /// String 12 digit intergers that to be converted to UPC-A barcode.
        /// </param>
        /// <param name="scale">
        /// Scale is nothign.
        /// </param>
        /// <returns>
        /// Control image.
        /// </returns>
        public Image CreateBarCode(string txt, int scale)
        {
            Image img = null;

            // imageWidth = 1000;
            imageScale = scale;
            imageWidth = System.Convert.ToInt32(imageWidth * imageScale);
            int    imageHeightHolder = System.Convert.ToInt32(barCodeHeight * imageScale);
            string incomingString    = txt.ToUpper();

            if (incomingString.Length == 0)
            {
                return(img);
            }
            int numberOfChars = incomingString.Length;

            newBitmap = new Bitmap((imageWidth), imageHeightHolder, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            g         = Graphics.FromImage(newBitmap);
            g.ScaleTransform(imageScale, imageScale);
            Rectangle newRec = new Rectangle(0, 0, (imageWidth), imageHeightHolder);

            g.FillRectangle(new SolidBrush(Color.White), newRec);
            placeMarker = 0;
            txt         = txt.Substring(0, 11) + GetCheckSum(txt).ToString();
            int wholeSet = 0;

            for (wholeSet = 1; wholeSet <= System.Convert.ToInt32(incomingString.Length); wholeSet++)
            {
                int currentASCII = (int)Convert.ToChar((incomingString.Substring(wholeSet - 1, 1))) - 48;
                if (wholeSet == 1)
                {
                    DrawSet(UPCABegin, placeMarker, 0);
                    DrawSet(UPCALeft[currentASCII], placeMarker, 0);
                }
                else if (wholeSet <= 5)
                {
                    DrawSet(UPCALeft[currentASCII], placeMarker, 6);
                }
                else if (wholeSet == 6)
                {
                    DrawSet(UPCALeft[currentASCII], placeMarker, 6);
                    DrawSet(UPCAMiddle, placeMarker, 0);
                }
                else if (wholeSet <= 11)
                {
                    DrawSet(UPCARight[currentASCII], placeMarker, 6);
                }
                else if (wholeSet == 12)
                {
                    DrawSet(UPCARight[currentASCII], placeMarker, 0);
                    DrawSet(UPCAEnd, placeMarker, 0);
                }
            }

            System.Drawing.Font font = new System.Drawing.Font("Verdana, Bold", 7);
            try
            {
                g.DrawString(txt.Substring(0, 1), font, Brushes.Black, new System.Drawing.PointF(0, 15));
                g.DrawString(txt.Substring(1, 5), font, Brushes.Black, new System.Drawing.PointF(22, 15));
                g.DrawString(txt.Substring(6, 5), font, Brushes.Black, new System.Drawing.PointF(60, 15));
                g.DrawString(txt.Substring(11, 1), font, Brushes.Black, new System.Drawing.PointF(108, 15));
            }
            finally
            {
                font.Dispose();
            }
            img = Image.FromHbitmap(newBitmap.GetHbitmap());
            return(img);
        }
Esempio n. 53
0
        public void Draw(TimeLineDrawParameter parameter)
        {
            if (parameter == null)
            {
                return;
            }

            area         = new SolidBrush(PPDEditorSkin.Skin.TimeLineSeekAreaColor);
            border       = new Pen(PPDEditorSkin.Skin.TimeLineSeekAreaBorderColor);
            text         = new SolidBrush(PPDEditorSkin.Skin.TimeLineTextColor);
            hline        = new Pen(PPDEditorSkin.Skin.TimeLineHorizontalLineColor);
            time         = new Pen(PPDEditorSkin.Skin.TimeLineCurrentTimeColor);
            vline1       = new Pen(PPDEditorSkin.Skin.TimeLineVerticalLineColor1);
            vline2       = new Pen(PPDEditorSkin.Skin.TimeLineVerticalLineColor2);
            vline3       = new Pen(PPDEditorSkin.Skin.TimeLineVerticalLineColor3);
            vline4       = new Pen(PPDEditorSkin.Skin.TimeLineVerticalLineColor4);
            vline5       = new Pen(PPDEditorSkin.Skin.TimeLineVerticalLineColor5);
            selection    = new SolidBrush(PPDEditorSkin.Skin.TimeLineSelectionAreaColor);
            selectedmark = new SolidBrush(PPDEditorSkin.Skin.TimeLineSelectedMarkColor);
            holdExtent   = new SolidBrush(PPDEditorSkin.Skin.TimeLineHoldExtentColor);

            parameter.Graphics.FillRectangle(Brushes.White, new Rectangle(0, 0, parameter.Width, parameter.Height));
            if (parameter.BackGroundImage != null && parameter.Width > 0 && parameter.Height > 0)
            {
                parameter.Graphics.DrawImage(parameter.BackGroundImage, 0, 0);
            }
            parameter.Graphics.FillRectangle(area, 0, 0, parameter.Width, PPDEditorSkin.Skin.TimeLineHeight);
            parameter.Graphics.DrawLine(border, 0, PPDEditorSkin.Skin.TimeLineHeight - 1, parameter.Width, PPDEditorSkin.Skin.TimeLineHeight - 1);
            var rows     = WindowUtility.TimeLineForm.RowManager.OrderedVisibleRows;
            var visibles = WindowUtility.TimeLineForm.RowManager.Visibilities;
            //hline
            int iter = 0;

            foreach (var row in rows)
            {
                parameter.Graphics.FillRectangle(PPDEditorSkin.Skin.TimeLineBackGroundColors[row],
                                                 new Rectangle(0, PPDEditorSkin.Skin.TimeLineHeight + PPDEditorSkin.Skin.TimeLineRowHeight * iter + 1,
                                                               parameter.Width, PPDEditorSkin.Skin.TimeLineRowHeight));
                iter++;
            }
            if (parameter.Sheet != null)
            {
                //areaselection
                if (parameter.Sheet.RecStart.X != -1 && parameter.Sheet.RecStart.Y != -1)
                {
                    float startx = (parameter.Sheet.RecStart.X <= parameter.Sheet.RecEnd.X ? parameter.Sheet.RecStart.X : parameter.Sheet.RecEnd.X) * parameter.BPM / 60 * parameter.Interval;
                    float width  = Math.Abs(parameter.Sheet.RecStart.X - parameter.Sheet.RecEnd.X) * parameter.BPM / 60 * parameter.Interval;
                    int   starty = (parameter.Sheet.RecStart.Y <= parameter.Sheet.RecEnd.Y ? parameter.Sheet.RecStart.Y : parameter.Sheet.RecEnd.Y);
                    var   height = Math.Min(rows.Length, Math.Abs(parameter.Sheet.RecStart.Y - parameter.Sheet.RecEnd.Y) + 1);
                    parameter.Graphics.FillRectangle(selection, startx - parameter.LeftOffset,
                                                     starty * (PPDEditorSkin.Skin.TimeLineRowHeight) + PPDEditorSkin.Skin.TimeLineHeight,
                                                     width, height * (PPDEditorSkin.Skin.TimeLineRowHeight) + 1);
                }
            }
            iter = 0;
            foreach (var row in rows)
            {
                parameter.Graphics.DrawLine(hline, 0,
                                            PPDEditorSkin.Skin.TimeLineHeight + PPDEditorSkin.Skin.TimeLineRowHeight * (iter + 1),
                                            parameter.Width, PPDEditorSkin.Skin.TimeLineHeight + PPDEditorSkin.Skin.TimeLineRowHeight * (iter + 1));
                iter++;
            }
            int offset       = -(int)(parameter.BPMStart * parameter.Interval / parameter.BPM);
            int startpos     = offset + parameter.LeftOffset;
            int startcount   = startpos / parameter.Interval;
            int startdrawpos = startcount * parameter.Interval - startpos;
            var font         = new System.Drawing.Font("MS ゴシック", 10);

            for (int i = 0; i *parameter.Interval + startdrawpos < parameter.Width; i++)
            {
                if (parameter.DisplayMode <= DisplayLineMode.SixtyFourth)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        if (parameter.DisplayMode >= DisplayLineMode.Fourth && j == 0)
                        {
                            parameter.Graphics.DrawLine(vline1, startdrawpos + parameter.Interval * (4 * i + j) / 4, 0, startdrawpos + parameter.Interval * (4 * i + j) / 4, parameter.Height);
                        }
                        if (parameter.DisplayMode >= DisplayLineMode.Eigth && j == 2)
                        {
                            parameter.Graphics.DrawLine(vline2, startdrawpos + parameter.Interval * (4 * i + j) / 4, 0, startdrawpos + parameter.Interval * (4 * i + j) / 4, parameter.Height);
                        }
                        if (parameter.DisplayMode >= DisplayLineMode.Sixteenth && (j == 1 || j == 3))
                        {
                            parameter.Graphics.DrawLine(vline3, startdrawpos + parameter.Interval * (4 * i + j) / 4, 0, startdrawpos + parameter.Interval * (4 * i + j) / 4, parameter.Height);
                        }
                        if (parameter.DisplayMode >= DisplayLineMode.ThirtySecond)
                        {
                            parameter.Graphics.DrawLine(vline4, startdrawpos + parameter.Interval * (8 * i + j * 2 + 1) / 8, 10, startdrawpos + parameter.Interval * (8 * i + j * 2 + 1) / 8, parameter.Height);
                        }
                        if (parameter.DisplayMode >= DisplayLineMode.SixtyFourth)
                        {
                            parameter.Graphics.DrawLine(vline5, startdrawpos + parameter.Interval * (16 * i + j * 4 + 1) / 16, 10, startdrawpos + parameter.Interval * (16 * i + j * 4 + 1) / 16, parameter.Height);
                            parameter.Graphics.DrawLine(vline5, startdrawpos + parameter.Interval * (16 * i + j * 4 + 3) / 16, 10, startdrawpos + parameter.Interval * (16 * i + j * 4 + 3) / 16, parameter.Height);
                        }
                    }
                }
                else if (parameter.DisplayMode >= DisplayLineMode.Twelfth && parameter.DisplayMode <= DisplayLineMode.FourthEighth)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (j == 0)
                        {
                            parameter.Graphics.DrawLine(vline1, startdrawpos + parameter.Interval * (4 * i + j) / 4, 0, startdrawpos + parameter.Interval * (4 * i + j) / 4, parameter.Height);
                        }
                        if (parameter.DisplayMode >= DisplayLineMode.Twelfth && (j == 1 || j == 2))
                        {
                            parameter.Graphics.DrawLine(vline2, startdrawpos + parameter.Interval * (3 * i + j) / 3, 0, startdrawpos + parameter.Interval * (3 * i + j) / 3, parameter.Height);
                        }
                        if (parameter.DisplayMode >= DisplayLineMode.TwentyFourth)
                        {
                            parameter.Graphics.DrawLine(vline3, startdrawpos + parameter.Interval * (6 * i + j * 2 + 1) / 6, 0, startdrawpos + parameter.Interval * (6 * i + j * 2 + 1) / 6, parameter.Height);
                        }
                        if (parameter.DisplayMode >= DisplayLineMode.FourthEighth)
                        {
                            parameter.Graphics.DrawLine(vline4, startdrawpos + parameter.Interval * (12 * i + j * 4 + 1) / 12, 10, startdrawpos + parameter.Interval * (12 * i + j * 4 + 1) / 12, parameter.Height);
                            parameter.Graphics.DrawLine(vline4, startdrawpos + parameter.Interval * (12 * i + j * 4 + 3) / 12, 10, startdrawpos + parameter.Interval * (12 * i + j * 4 + 3) / 12, parameter.Height);
                        }
                    }
                }
                int count = (startcount + i).ToString().Length;
                if ((startcount + i) % parameter.BeatSplitCount == 0)
                {
                    parameter.Graphics.DrawString(((startcount + i) / parameter.BeatSplitCount).ToString(), font, text, new PointF(i * parameter.Interval + startdrawpos - font.GetHeight() / 2 * count / 2, 0));
                }
            }
            font.Dispose();
            float drawstarttime = (float)(parameter.LeftOffset - 10) / parameter.Interval / parameter.BPM * 60;
            float drawendtime   = (float)(parameter.LeftOffset + parameter.Width + 10) / parameter.Interval / parameter.BPM * 60;

            LayerDisplay[] layers = WindowUtility.LayerManager.AllLayerDisplay;
            if (layers != null)
            {
                foreach (var layer in layers)
                {
                    var sheet = layer.PPDData;
                    mark     = new SolidBrush(layer.MarkColor);
                    diffmark = new SolidBrush(Color.FromArgb(64 * layer.MarkColor.A / 255, layer.MarkColor));
                    bool isSelectedLayer = sheet == WindowUtility.LayerManager.SelectedPpdSheet;
                    iter = 0;
                    foreach (var row in rows)
                    {
                        var times = sheet.Data[row].Keys;
                        for (var i = 0; i < times.Count; i++)
                        {
                            var f = times[i];
                            sheet.Data[row].TryGetValue(f, out Mark mk);
                            if (!visibles[(int)mk.Type])
                            {
                                continue;
                            }
                            var exmk = mk as ExMark;
                            if (exmk == null)
                            {
                                if (f >= drawstarttime && f <= drawendtime)
                                {
                                    if (isSelectedLayer && sheet.FocusedMark[0] == row && sheet.FocusedMark[1] == sheet.Data[row].IndexOfKey(f))
                                    {
                                        parameter.Graphics.FillEllipse(selectedmark, (f * parameter.BPM / 60 * parameter.Interval - parameter.LeftOffset) - CircleWidth / 2,
                                                                       PPDEditorSkin.Skin.TimeLineHeight + PPDEditorSkin.Skin.TimeLineRowHeight * (iter + 0.5f) - CircleWidth / 2, CircleWidth, CircleWidth);
                                    }
                                    else
                                    {
                                        parameter.Graphics.FillEllipse(isSelectedLayer ? mark : diffmark, (f * parameter.BPM / 60 * parameter.Interval - parameter.LeftOffset) - CircleWidth / 2,
                                                                       PPDEditorSkin.Skin.TimeLineHeight + PPDEditorSkin.Skin.TimeLineRowHeight * (iter + 0.5f) - CircleWidth / 2,
                                                                       CircleWidth, CircleWidth);
                                    }
                                }
                            }
                            else
                            {
                                var drawLongNote   = (f >= drawstarttime && f <= drawendtime) || (exmk.EndTime >= drawstarttime && exmk.EndTime <= drawendtime);
                                var holdExtentTime = f + 5 + PPDSetting.Setting.GoodArea;
                                var drawHoldExtent = holdExtentTime >= drawstarttime && holdExtentTime <= drawendtime;

                                if (WindowUtility.MainForm.ShowHoldExtent && (drawLongNote || drawHoldExtent))
                                {
                                    if (!exmk.IsScratch && (exmk.NoteType == PPDFramework.NoteType.AC || exmk.NoteType == PPDFramework.NoteType.ACFT))
                                    {
                                        var hasNextTime = i + 1 < times.Count;
                                        var height      = PPDEditorSkin.Skin.TimeLineRowHeight - 3;
                                        var rectX       = f * parameter.BPM / 60 * parameter.Interval - parameter.LeftOffset;
                                        var rectY       = PPDEditorSkin.Skin.TimeLineHeight + PPDEditorSkin.Skin.TimeLineRowHeight * (iter + 0.5f) - height / 2;
                                        var width       = (5 + PPDSetting.Setting.GoodArea) * parameter.BPM / 60 * parameter.Interval;
                                        var nextX       = float.MaxValue;
                                        if (hasNextTime)
                                        {
                                            nextX = times[i + 1] * parameter.BPM / 60 * parameter.Interval - parameter.LeftOffset;
                                            if (rectX + width >= nextX)
                                            {
                                                width = nextX - rectX;
                                            }
                                        }
                                        var rect = new Rectangle((int)rectX, (int)rectY, (int)width, height);
                                        parameter.Graphics.FillRectangle(holdExtent, rect);
                                        var x = (int)((f + 5 + PPDSetting.Setting.GoodArea) * parameter.BPM / 60 * parameter.Interval - parameter.LeftOffset);
                                        if (nextX > x)
                                        {
                                            parameter.Graphics.DrawLine(Pens.Black, x, rect.Top + 8, x, rect.Bottom - 8);
                                        }
                                        x = (int)((f + 5 + PPDSetting.Setting.CoolArea) * parameter.BPM / 60 * parameter.Interval - parameter.LeftOffset);
                                        if (nextX > x)
                                        {
                                            parameter.Graphics.DrawLine(Pens.Black, x, rect.Top + 4, x, rect.Bottom - 4);
                                        }
                                        x = (int)((f + 5) * parameter.BPM / 60 * parameter.Interval - parameter.LeftOffset);
                                        if (nextX > x)
                                        {
                                            parameter.Graphics.DrawLine(Pens.Black, x, rect.Top, x, rect.Bottom);
                                        }
                                        x = (int)((f + 5 - PPDSetting.Setting.CoolArea) * parameter.BPM / 60 * parameter.Interval - parameter.LeftOffset);
                                        if (nextX > x)
                                        {
                                            parameter.Graphics.DrawLine(Pens.Black, x, rect.Top + 4, x, rect.Bottom - 4);
                                        }
                                        x = (int)((f + 5 - PPDSetting.Setting.GoodArea) * parameter.BPM / 60 * parameter.Interval - parameter.LeftOffset);
                                        if (nextX > x)
                                        {
                                            parameter.Graphics.DrawLine(Pens.Black, x, rect.Top + 8, x, rect.Bottom - 8);
                                        }
                                    }
                                }

                                if (drawLongNote)
                                {
                                    var rect = new Rectangle((int)(f * parameter.BPM / 60 * parameter.Interval - parameter.LeftOffset),
                                                             (int)(PPDEditorSkin.Skin.TimeLineHeight + PPDEditorSkin.Skin.TimeLineRowHeight * (iter + 0.5f) - CircleWidth / 2),
                                                             (int)((exmk.EndTime - f) * parameter.BPM / 60 * parameter.Interval), CircleWidth);
                                    if (isSelectedLayer && sheet.FocusedMark[0] == row && sheet.FocusedMark[1] == sheet.Data[row].IndexOfKey(f))
                                    {
                                        parameter.Graphics.FillRectangle(selectedmark, rect);
                                    }
                                    else
                                    {
                                        parameter.Graphics.FillRectangle(isSelectedLayer ? mark : diffmark, rect);
                                    }
                                }
                            }
                        }
                        iter++;
                    }
                }
            }
            var events = WindowUtility.EventManager.GetEventsWithinTime(drawstarttime, drawendtime);

            foreach (float eventtime in events)
            {
                DrawChange(parameter, eventtime, 0, rows.Length, PPDEditor.Properties.Resources.eventmark);
            }
            events = WindowUtility.SoundManager.GetSoundChangeWithinTime(drawstarttime, drawendtime);
            foreach (float eventtime in events)
            {
                DrawChange(parameter, eventtime, 14, rows.Length, PPDEditor.Properties.Resources.soundmark);
            }
            events = WindowUtility.KasiEditor.GetKasiChangeWithinTime(drawstarttime, drawendtime);
            foreach (float eventtime in events)
            {
                DrawChange(parameter, eventtime, 28, rows.Length, PPDEditor.Properties.Resources.lylicsmark);
            }
            var pos = (float)(parameter.CurrentTime * parameter.BPM / 60 * parameter.Interval);

            if (pos - parameter.LeftOffset >= -5 && pos - parameter.LeftOffset <= parameter.Width + 5)
            {
                parameter.Graphics.DrawLine(time, new PointF(pos - parameter.LeftOffset, PPDEditorSkin.Skin.TimeLineHeight), new PointF(pos - parameter.LeftOffset, parameter.Height));
                parameter.Graphics.DrawRectangle(time, pos - 5 - parameter.LeftOffset, 0, 10, PPDEditorSkin.Skin.TimeLineHeight - 1);
            }
        }
Esempio n. 54
0
        //
        private void btNextBack_Click(object sender, EventArgs e)
        {
            Button bt  = (sender as Button);
            int    Old = idxPn;

            if (idxPn == 1 && bt == btNext && !ProfNorm)
            {
                FillCr();
            }
            if (idxPn == 3 && bt == btNext && !ProfNorm)
            {
                FillMatrix();
            }
            if (bt == btBack)
            {
                if (idxPn > 0 && idxPn < 3)
                {
                    idxPn--;
                    if (idxPn == 1 && !ProfNorm)
                    {
                        idxPn = 0;
                    }
                }
                else
                if (idxPn == 5)
                {
                    idxPn  = 3;
                    idxCmp = 8;
                }
                else
                if (!ProfNorm)
                {
                    if (idxCmp == 0)
                    {
                        idxPn = 1;
                    }
                }
                else
                {
                    idxPn = 3;
                }
                //
                if (idxPn > 2 && idxPn < 5)
                {
                    if (!ProfNorm)
                    {
                        idxCmp--;
                        idxPn = 3;
                    }
                }
                else
                {
                    idxCmp = -1;
                }
            }
            else
            {
                if (idxPn < 3)
                {
                    idxPn++;
                    if (idxPn == 2 && !ProfNorm)
                    {
                        idxPn = 3;
                    }
                }
                else
                if (!ProfNorm)
                {
                    if (idxCmp == 7)
                    {
                        idxPn = 5;
                    }
                }
                else
                {
                    idxPn = 4;
                }
                //
                if (idxPn > 2 && idxPn < 5)
                {
                    if (!ProfNorm)
                    {
                        idxCmp++;
                        idxPn = 3;
                    }
                }
                else
                {
                    idxCmp = -1;
                }
            }
            if (idxPn == 3 && Old == 2 && GetSum() != 1)
            {
                idxCmp = -1;
                idxPn  = 2;
                MessageBox.Show("Неверная сумма коэффициентов!");
                return;
            }
            btBack.Visible = idxPn > 0;
            btNext.Visible = idxPn < arrPn.Length - 1;
            for (int i = 0; i < arrPn.Length; i++)
            {
                arrPn[i].Visible = i == idxPn;
            }
            for (int i = 0; i < arrLb.Length; i++)
            {
                if (idxPn == 0 && i == 0)
                {
                    arrLb[i].BackColor = Color.Gainsboro;
                }
                else
                if ((idxPn == 1 || idxPn == 2) && i == 1)
                {
                    arrLb[i].BackColor = Color.Gainsboro;
                }
                else
                if ((idxPn == 3 || idxPn == 4) && i == 2)
                {
                    arrLb[i].BackColor = Color.Gainsboro;
                }
                else
                if (idxPn == 5 && i == 3)
                {
                    arrLb[i].BackColor = Color.Gainsboro;
                }
                else
                {
                    arrLb[i].BackColor = Color.White;
                }
            }
            lbCmp.Visible = idxPn > 2 && idxPn < 5;
            lbStep2.Text  = "Сравнение альтернатив";
            if (lbCmp.Visible)
            {
                lbCmp.Text    = dgCr.Rows[idxCmp].HeaderCell.Value.ToString();
                lbStep2.Text += "(" + (idxCmp + 1) + "/8)";
            }
            if (idxPn > 0 && idxPn < 5)
            {
                btProf.Visible = idxPn % 2 == 1;
                btNorm.Visible = !btProf.Visible;
            }
            if (idxPn == 1 && Old == 0)
            {
                Start();
            }
            if (idxPn == 2)
            {
                int nCr = aCr.Length;
                for (int i = 0; i < nCr; i++)
                {
                    dgCr.Rows[i].Cells[0].Value = aCr[i].ToString();
                }
                lbSum.Text = "Сумма: " + GetSum();
            }
            int nPh = dgPh.Rows[0].Cells[0].Value != null ? dgPh.Rows.Count : 0;

            btExit.Visible = idxPn == arrPn.Length - 1;
            if (idxPn == 1 || idxPn == 3)
            {
                int nRows = idxPn == 3 ? nPh : dgCr.Rows.Count;
                if (aLb != null)
                {
                    for (int i = 0; i < aLb.Length; i++)
                    {
                        aLb[i].Dispose();
                    }
                }
                if (nRows > 0)
                {
                    System.Drawing.Font Fnt = new System.Drawing.Font("Courier New", 9.75F,
                                                                      System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
                    int d = 3;
                    aLb = new Label[nRows];
                    Panel Pn  = idxPn == 3 ? pnPhone : pnCr;
                    int   hLb = 25;
                    Pn.Height = nRows * (d + hLb) + d + 2;
                    int wLb = (Pn.ClientSize.Width - d * (nRows + 1)) / nRows;
                    for (int i = 0; i < nRows; i++)
                    {
                        Label lb = new Label();
                        lb.Tag         = i * 100;
                        lb.BackColor   = System.Drawing.Color.Gainsboro;
                        lb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                        lb.Font        = Fnt;
                        lb.Location    = new System.Drawing.Point(d, d + i * (d + hLb));
                        lb.Name        = "_" + i;
                        lb.Size        = new System.Drawing.Size(wLb, hLb);
                        lb.Text        = (idxPn == 3 ? dgPh.Rows[i].Cells[0].Value : dgCr.Rows[i].HeaderCell.Value).ToString();
                        lb.TextAlign   = System.Drawing.ContentAlignment.MiddleCenter;
                        lb.MouseMove  += new System.Windows.Forms.MouseEventHandler(this.lbPhone_MouseMove);
                        lb.MouseDown  += new System.Windows.Forms.MouseEventHandler(this.lbPhone_MouseDown);
                        lb.MouseUp    += new System.Windows.Forms.MouseEventHandler(this.lbPhone_MouseUp);
                        //lb.MouseEnter += new System.EventHandler(this.lbPhone_MouseEnter);
                        lb.MouseLeave += new System.EventHandler(this.lbPhone_MouseLeave);
                        Pn.Controls.Add(lb);
                        aLb[i] = lb;
                    }
                    Fnt.Dispose();
                    aTb = new int[nRows, nRows];
                    for (int i = 0; i < nRows; i++)
                    {
                        for (int j = 0; j < nRows; j++)
                        {
                            aTb[i, j] = j == 0 ? i : -1;
                        }
                    }
                }
            }
            else
            if (idxPn == 4 && nPh > 0)
            {
                SetMatrix(nPh);
            }
        }
Esempio n. 55
0
        public void CreateCheckCodeImage(int length)
        {
            if (ConfigurationManager.AppSettings["VerificationCode"] == null)
            {
                throw new Exception("請設定ConfigurationManager.AppSettings['VerificationCode']");
            }

            string text = ConfigurationManager.AppSettings["VerificationCode"];

            string letters    = "1,2,3,4,5,6,7,8,9,Q,W,E,R,T,Y,U,A,S,D,F,G,H,J,K,L,Z,X,C,V,B,N,M,w,e,r,t,y,u,i,p,a,s,d,f,g,h,j,k,z,x,c,v,b,n,m";
            var    chars      = letters.Split(',');
            var    charRandom = new Random();
            var    code       = string.Empty;

            for (var i = 0; i < length; i++)
            {
                code += chars[charRandom.Next(chars.Length)];
            }

            HttpContext.Current.Session[text] = code;
            System.Drawing.Bitmap   img = new System.Drawing.Bitmap((code.Length * 20), 40);//產生圖片,寬20*位數,高40像素
            System.Drawing.Graphics g   = Graphics.FromImage(img);


            //生成隨機生成器
            Random random    = new Random(Guid.NewGuid().GetHashCode());
            int    int_Red   = 0;
            int    int_Green = 0;
            int    int_Blue  = 0;

            int_Red   = random.Next(256); //產生0~255
            int_Green = random.Next(256); //產生0~255
            int_Blue  = (int_Red + int_Green > 400 ? 0 : 400 - int_Red - int_Green);
            int_Blue  = (int_Blue > 255 ? 255 : int_Blue);

            //清空圖片背景色
            g.Clear(Color.FromArgb(int_Red, int_Green, int_Blue));

            //畫圖片的背景噪音線
            for (int i = 0; i <= 24; i++)
            {
                int x1 = random.Next(img.Width);
                int x2 = random.Next(img.Width);
                int y1 = random.Next(img.Height);
                int y2 = random.Next(img.Height);

                g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);

                g.DrawEllipse(new Pen(Color.DarkViolet), new System.Drawing.Rectangle(x1, y1, x2, y2));
            }

            Font font = new System.Drawing.Font("Arial", 20, (System.Drawing.FontStyle.Bold));

            System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Blue, Color.DarkRed, 1.2F, true);

            g.DrawString(code, font, brush, 2, 2);
            for (int i = 0; i <= 99; i++)
            {
                //畫圖片的前景噪音點
                int x = random.Next(img.Width);
                int y = random.Next(img.Height);

                img.SetPixel(x, y, Color.FromArgb(random.Next()));
            }

            //畫圖片的邊框線
            g.DrawRectangle(new Pen(Color.Silver), 0, 0, img.Width - 1, img.Height - 1);

            bytes = imageToByteArray(img);
            image = img;

            font.Dispose();
            g.Dispose();
            image.Dispose();

            //return img_byte;
        }
        protected override void OnPaint(PaintEventArgs pe)
        {
            // Calling the base class OnPaint
            base.OnPaint(pe);



            Pen drawRedPen = new Pen(Color.Red, 2);

            System.Drawing.Font       drawFont      = new System.Drawing.Font(FontFamily.GenericMonospace, 8.0F);
            System.Drawing.SolidBrush drawBrush     = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
            System.Drawing.SolidBrush drawBrushBlue = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
            System.Drawing.SolidBrush drawBrushRed  = new System.Drawing.SolidBrush(System.Drawing.Color.Red);

            bmpBackground.MakeTransparent(Color.Yellow);
            pe.Graphics.DrawImageUnscaled(bmpBackground, 0, 0);

            double a = T_MID;
            double b = T_EXPO;
            double val;

            int[] curvepoints = new int[75];

            for (int i = 0; i < 11; i++)
            {
                int mid  = (int)(100 * a);
                int expo = (int)(100 * b);
                int tmp  = 10 * i - mid;
                int y    = 1;
                if (tmp > 0)
                {
                    y = 100 - mid;
                }
                if (tmp < 0)
                {
                    y = mid;
                }
                lookupT[i] = (int)(10 * mid + tmp * (100 - expo + tmp * tmp * expo / (y * y)) / 10);
            }



            //4x4 pixel pint fir drawing
            Bitmap   bm  = new Bitmap(1, 1);
            Graphics gfx = Graphics.FromImage(bm);

            gfx.FillRectangle(drawBrushBlue, 0, 0, 3, 3);

            Bitmap   bl   = new Bitmap(3, 3);
            Graphics gfx1 = Graphics.FromImage(bl);

            gfx1.FillRectangle(drawBrushRed, 0, 0, 5, 5);

            //Quick hack to scale the original rc rate box to this control size... I was lazy to rewrite the calculations...
            if (got_data)
            {
                for (int i = 0; i < 70; i++)
                {
                    int tmp       = 1000 / 70 * i;
                    int tmp2      = tmp / 100;
                    int rccommand = lookupT[tmp2] + (tmp - tmp2 * 100) * (lookupT[tmp2 + 1] - lookupT[tmp2]) / 100;
                    val = rccommand * 70 / 1000;
                    pe.Graphics.DrawImageUnscaled(bm, (int)((double)(i) * 1.9f) + 9, 5 + (int)((70 - val) * 1.2f));
                    curvepoints[i] = (int)((70 - val) * 1.2f);
                }
                curvepoints[70] = curvepoints[69];
                curvepoints[71] = curvepoints[69];
                curvepoints[72] = curvepoints[69];
                curvepoints[73] = curvepoints[69];



//                for (int i =0;i<20;i++) {
                pe.Graphics.DrawImageUnscaled(bl, (int)((double)((Math.Max(1100, Throttle) - 1100) * 70 / 900) * 1.9f) + 9, curvepoints[(int)((double)((Math.Max(1100, Throttle) - 1100) * 70 / 900))] + 2);
//                    }

                pe.Graphics.DrawString("Mid:" + String.Format("{0:0.00}", T_MID), drawFont, drawBrush, 10, 5);
                pe.Graphics.DrawString("Expo:" + String.Format("{0:0.00}", T_EXPO), drawFont, drawBrush, 10, 15);
            }
            else
            {
                pe.Graphics.DrawString("No Data", drawFont, drawBrush, 10, 5);
            }

            gfx.Dispose();
            gfx1.Dispose();
            bl.Dispose();
            bm.Dispose();
            drawBrush.Dispose();
            drawBrushBlue.Dispose();
            drawFont.Dispose();
            drawRedPen.Dispose();
        }
Esempio n. 57
0
        /// <summary>
        /// Draw the day/hour grid and hour labels for the frame of the calendar
        /// </summary>
        /// <param name="pe">PaintEventArgs for drawing graphics on the control</param>
        public void DrawCalendarFrame(PaintEventArgs pe)
        {
            int width  = this.ClientRectangle.Width - leftMargin - rightMargin;
            int height = 1920;
            int left   = this.ClientRectangle.Left + leftMargin;
            int top    = this.ClientRectangle.Top + topMargin;
            int right  = left + width;
            int bottom = top + height;

            // fire the resize event with the needed positions for the day dividers
            CalendarResizedEventArgs r = new CalendarResizedEventArgs
            {
                dayStartPositions = new int[] { left, left + width / 5, left + 2 * width / 5, left + 3 * width / 5, left + 4 * width / 5, right },
            };

            ResizeEvent?.Invoke(this, r);

            Pen pen = new Pen(Color.LightGray);

            // draw horizontal divider lines of calendar
            int startX;

            for (int i = 0; i < 48; i++)
            {
                if (i % 2 == 0)
                {
                    startX = 0;
                }
                else
                {
                    startX = leftMargin;
                }
                pe.Graphics.DrawLine(pen, new Point(startX, top + 40 * i), new Point(right, top + 40 * i));
            }

            pen.Color = Color.Black;

            // draw vertical divider lines of calendar
            pe.Graphics.DrawLine(pen, new Point(left, top), new Point(left, bottom));                      // left vertical border line
            pe.Graphics.DrawLine(pen, new Point(left + width / 5, top), new Point(left + width / 5, bottom));
            pe.Graphics.DrawLine(pen, new Point(left + 2 * width / 5, top), new Point(left + 2 * width / 5, bottom));
            pe.Graphics.DrawLine(pen, new Point(left + 3 * width / 5, top), new Point(left + 3 * width / 5, bottom));
            pe.Graphics.DrawLine(pen, new Point(left + 4 * width / 5, top), new Point(left + 4 * width / 5, bottom));
            pe.Graphics.DrawLine(pen, new Point(right, top), new Point(right, bottom));                    // right vertical border line

            // draw bottom border line
            pen.Width *= 2;
            pe.Graphics.DrawLine(pen, new Point(left, bottom), new Point(right, bottom));

            // finished with pen for drawing, so dispose
            pen.Dispose();

            // prepare to draw hour divider labels (using SolidBrush)
            System.Drawing.Font         drawFont   = new System.Drawing.Font("Segoe UI", 12);
            System.Drawing.SolidBrush   brush      = new System.Drawing.SolidBrush(System.Drawing.Color.Gray);
            System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();

            // draw label for each hour
            for (int i = 0; i < 24; i++)
            {
                pe.Graphics.DrawString(GetHourLabel(i), drawFont, brush, 5, top + 80 * i, drawFormat);
            }

            // dispose of string drawing resources
            drawFont.Dispose();
            brush.Dispose();
            drawFormat.Dispose();
        }
Esempio n. 58
0
        public static System.IO.MemoryStream GenerateCheckCode(out string checkCode)
        {
            checkCode = string.Empty;
            System.Drawing.Color color = System.Drawing.ColorTranslator.FromHtml("#1AE61A");
            char[] array = new char[]
            {
                '2',
                '3',
                '4',
                '5',
                '6',
                '8',
                '9',
                'A',
                'B',
                'C',
                'D',
                'E',
                'F',
                'G',
                'H',
                'J',
                'K',
                'L',
                'M',
                'N',
                'P',
                'R',
                'S',
                'T',
                'W',
                'X',
                'Y'
            };
            System.Random random = new System.Random();
            for (int i = 0; i < 4; i++)
            {
                checkCode += array[random.Next(array.Length)];
            }
            int width = 85;

            System.Drawing.Bitmap   bitmap   = new System.Drawing.Bitmap(width, 30);
            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
            System.Random           random2  = new System.Random(System.DateTime.Now.Millisecond);
            System.Drawing.Brush    brush    = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(4683611));
            graphics.Clear(System.Drawing.ColorTranslator.FromHtml("#EBFDDF"));
            using (System.Drawing.StringFormat stringFormat = new System.Drawing.StringFormat())
            {
                stringFormat.Alignment     = System.Drawing.StringAlignment.Center;
                stringFormat.LineAlignment = System.Drawing.StringAlignment.Center;
                stringFormat.FormatFlags   = System.Drawing.StringFormatFlags.NoWrap;
                System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
                float num  = -25f;
                float num2 = 0f;
                graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                for (int i = 0; i < checkCode.Length; i++)
                {
                    int num3 = random2.Next(20, 24);
                    System.Drawing.Font  font  = ImageHelper.CreateFont(IOHelper.GetMapPath("/fonts/checkCode.ttf"), (float)num3, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0);
                    System.Drawing.SizeF sizeF = graphics.MeasureString(checkCode[i].ToString(), font);
                    matrix.RotateAt((float)random2.Next(-15, 10), new System.Drawing.PointF(num + sizeF.Width / 2f, num2 + sizeF.Height / 2f));
                    graphics.Transform = matrix;
                    graphics.DrawString(checkCode[i].ToString(), font, System.Drawing.Brushes.Green, new System.Drawing.RectangleF(num, num2, (float)bitmap.Width, (float)bitmap.Height), stringFormat);
                    num  += sizeF.Width * 3f / 5f;
                    num2 += 0f;
                    graphics.RotateTransform(0f);
                    matrix.Reset();
                    font.Dispose();
                }
            }
            System.Drawing.Pen     pen          = new System.Drawing.Pen(System.Drawing.Color.Black, 0f);
            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
            System.IO.MemoryStream result;
            try
            {
                bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
                result = memoryStream;
            }
            finally
            {
                bitmap.Dispose();
                graphics.Dispose();
            }
            return(result);
        }
Esempio n. 59
0
 public void Dispose()
 {
     Font?.Dispose();
 }
Esempio n. 60
0
        private void Load(string FontName, FontStyle FS)
        {
            try
            {
                GlyphInfo[] GI = Glyphs[FontName];
                if (GI != null)
                {
                    GlyphInfo = GI;
                    return;
                }
            }
            catch (Exception)
            {
            }

            System.Drawing.Font FF = null;
            try
            {
                FF = new System.Drawing.Font(FontName, 400, FS);
            }
            catch (Exception)
            {
                IsModernType = true;
            }
            if (FF != null)
            {
                FF.Dispose();
            }
            Bitmap   B = new Bitmap(500, 500);
            Graphics G = Graphics.FromImage(B);
            IntPtr   F = IntPtr.Zero;

            this.FontName  = FontName;
            this.FontStyle = FS;
            //this.IsModernType = ModernFont;
            if (IsModernType)
            {
                F = FeaturesW32.CreateFont(80, 0, 0, 0, 0, false, false, false, 255, 0, 0, 0, 16, FontName);
            }
            else
            {
                F = FeaturesW32.CreateFont(400, 0, 0, 0, 600, false, false, false, 0, 0, 0, 0, 2, FontName);
            }

            IntPtr hdc = G.GetHdc();

            FeaturesW32.SelectObject(hdc, F);


            FeaturesW32.GLYPHMETRICS Metrics;
            FeaturesW32.TEXTMETRIC   lpMetrics = new FeaturesW32.TEXTMETRIC();
            FeaturesW32.GetTextMetrics(hdc, ref lpMetrics);

            float Scale = (float)lpMetrics.tmHeight;

            Descent = (float)lpMetrics.tmDescent / Scale;
            double ModernyTrans = (float)lpMetrics.tmDescent / Scale;

            for (int i = 0; i < 256; i++)
            {
                try
                {
                    GlyphInfo[i] = new GlyphInfo();
                    if (!IsModernType)
                    {
                        GlyphInfo[i].Curves = FeaturesW32.GetOutLine(hdc, Scale, (Char)i, out Metrics);
                    }
                    else
                    {
                        GlyphInfo[i].Curves = FeaturesW32.GetModernOutLine(hdc, Scale, ModernyTrans, (Char)i, out Metrics);
                    }
                    if ((GlyphInfo[i].Curves.Count > 0) && (GlyphInfo[i].Curves[0].CrossProduct() >= 0))
                    {
                        GlyphInfo[i].Curves.Invert();
                    }


                    GlyphInfo[i].Deltax = (float)(Metrics.gmCellIncX) / (float)(lpMetrics.tmHeight);

                    agmf[i].gmfBlackBoxX       = (float)Metrics.gmBlackBoxX / (float)(lpMetrics.tmHeight);
                    agmf[i].gmfBlackBoxY       = (float)Metrics.gmBlackBoxY / (float)(lpMetrics.tmHeight);
                    GlyphInfo[i].BlackBoxY     = agmf[i].gmfBlackBoxY;
                    agmf[i].gmfCellIncX        = (float)Metrics.gmCellIncX / (float)(lpMetrics.tmHeight);
                    agmf[i].gmfCellIncY        = (float)Metrics.gmCellIncY / (float)(lpMetrics.tmHeight);
                    agmf[i].gmfptGlyphOrigin.X = (float)Metrics.gmptGlyphOrigin.x.Fract / (float)(lpMetrics.tmHeight);
                    agmf[i].gmfptGlyphOrigin.Y = (float)Metrics.gmptGlyphOrigin.y.Fract / (float)(lpMetrics.tmHeight);
                }
                catch
                {
                }
            }
            G.ReleaseHdc(hdc);
            Glyphs.Add(FontName, GlyphInfo);
        }