TranslateTransform() public method

public TranslateTransform ( float tx, float ty ) : void
tx float
ty float
return void
Ejemplo n.º 1
1
		public void Draw(Graphics g)
		{
			g.FillRectangle(SystemBrushes.AppWorkspace, Bounds);

			g.DrawRectangle(Pens.Black, mCanvasMarginWidth - 1, mCanvasMarginHeight - 1, 800 + 1, 600 + 1);

			g.TranslateTransform(mCanvasMarginWidth, mCanvasMarginHeight);
			GraphicsContainer containerState = g.BeginContainer();
			g.SmoothingMode = SmoothingMode.HighQuality;

			DrawCanvas(g);

			g.SmoothingMode = SmoothingMode.Default;
			g.EndContainer(containerState);
			g.TranslateTransform(-mCanvasMarginWidth, -mCanvasMarginHeight);


			//mCanvasBufferGraphics.FillRectangle(SystemBrushes.AppWorkspace, Bounds);

			//mCanvasBufferGraphics.DrawRectangle(Pens.Black, mCanvasMarginWidth - 1, mCanvasMarginHeight - 1, 800 + 1, 600 + 1);

			//DrawCanvas(mCanvasBufferGraphics);


			//Rectangle src = Bounds;
			//Rectangle dest = new Rectangle(0, 0, (int)(Bounds.Width * mScale), (int)(Bounds.Height * mScale));
			//dest.X = (Bounds.Width / 2) - (dest.Width / 2);
			//dest.Y = (Bounds.Height / 2) - (dest.Height / 2);

			//g.DrawImage(mCanvasBufferImage, dest, src, GraphicsUnit.Pixel);
		}
Ejemplo n.º 2
0
        public static Bitmap Rotate(Image b, int angle)
        {
            //弧度转换
            double radian = angle * System.Math.PI / 180.0;
            double cos    = System.Math.Cos(radian);
            double sin    = System.Math.Sin(radian);
            //原图的宽和高
            int w = b.Width;
            int h = b.Height;
            int W = (int)(System.Math.Max(System.Math.Abs(w * cos - h * sin), System.Math.Abs(w * cos + h * sin)));
            int H = (int)(System.Math.Max(System.Math.Abs(w * sin - h * cos), System.Math.Abs(w * sin + h * cos)));
            //目标位图
            Bitmap dsImage = new Bitmap(W, H);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //计算偏移量
            Point Offset = new Point((W - w) / 2, (H - h) / 2);
            //构造图像显示区域:让图像的中心与窗口的中心点一致
            Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
            Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            g.TranslateTransform(center.X, center.Y);
            g.RotateTransform(360 - angle);
            //恢复图像在水平和垂直方向的平移
            g.TranslateTransform(-center.X, -center.Y);
            g.DrawImage(b, rect);
            //重至绘图的所有变换
            g.ResetTransform();
            g.Save();
            g.Dispose();
            //dsImage.Save("yuancd.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            return(dsImage);
        }
Ejemplo n.º 3
0
        public override void Draw(System.Drawing.Graphics g)
        {
            int x, y, w, h;

            w    = 30; h = 30;
            x    = Location.X; y = Location.Y;
            Size = new Size(w, h);
            g.TranslateTransform(x, y);
            g.RotateTransform(Angle);

            //g.FillRectangle(Brushes.Gray, new Rectangle(0, 0, w, h));
            g.DrawRectangle(Pens.Black, new Rectangle(0, 0, w, h));
            g.DrawLine(Pens.Black, new Point(w, h / 2), new Point(w + 10, h / 2));

            g.DrawLine(Pens.Black, w / 2, 4, w / 2, h / 2 - 3);
            g.DrawLine(Pens.Black, w / 2, h / 2 + 3, w / 2, h - 4);
            g.DrawLine(Pens.Black, 4, h / 2, w / 2 - 3, h / 2);
            g.DrawLine(Pens.Black, w / 2 + 3, h / 2, w - 4, h / 2);

            g.DrawLine(Pens.Gray, 8, 8, w / 2 - 3, h / 2 - 3);
            g.DrawLine(Pens.Gray, w - 8, h - 8, w / 2 + 3, h / 2 + 3);
            g.DrawLine(Pens.Gray, 8, h - 8, w / 2 - 3, h / 2 + 3);
            g.DrawLine(Pens.Gray, w - 8, 8, w / 2 + 3, h / 2 - 3);

            g.DrawEllipse(Pens.Black, new Rectangle(2, 2, w - 4, h - 4));

            output.Draw(g);
            if (Selected)
            {
                g.DrawRectangle(Pens.Blue, new Rectangle(0, 0, Size.Width, Size.Height));
            }

            g.RotateTransform(-Angle);
            g.TranslateTransform(-x, -y);
        }
Ejemplo n.º 4
0
            private void PaintBackground(Graphics g, Control control, Rectangle clipRect)
            {
                Control parent = control;
                IPaintBackground asIpb = null;

                while (true)
                {
                    parent = parent.Parent;

                    if (parent == null)
                    {
                        break;
                    }

                    asIpb = parent as IPaintBackground;

                    if (asIpb != null)
                    {
                        break;
                    }
                }

                if (asIpb != null)
                {
                    Rectangle screenRect = control.RectangleToScreen(clipRect);
                    Rectangle parentRect = parent.RectangleToClient(screenRect);

                    int dx = parentRect.Left - clipRect.Left;
                    int dy = parentRect.Top - clipRect.Top;

                    g.TranslateTransform(-dx, -dy, MatrixOrder.Append);
                    asIpb.PaintBackground(g, parentRect);
                    g.TranslateTransform(dx, dy, MatrixOrder.Append);
                }
            }
Ejemplo n.º 5
0
      private void RenderSymbols( Graphics g )
      {
         float radius = _textureSize / 2 * 0.84f;
         float centerX = _textureSize / 2;
         float centerY = _textureSize / 2;
         var symbols = GetSymbols();

         using ( var font = new Font( "Meroitic - Hieroglyphics", _fontSize, FontStyle.Bold ) )
         {
            for ( int index = 0; index < _symbolCount; index++ )
            {
               char character = symbols[index];
               float arc = 360f / _symbolCount;
               float thetaDegrees = arc * index;
               float thetaRadians = AsRadians( thetaDegrees );

               var characterSize = MeasureCharacter( g, font, character );
               var centerPoint = new PointF( centerX - characterSize.Width / 2, centerY - characterSize.Height / 2 );

               float x = centerX + (float) Math.Cos( thetaRadians ) * radius;
               float y = centerY + (float) Math.Sin( thetaRadians ) * radius;

               g.TranslateTransform( x, y );
               g.RotateTransform( thetaDegrees + 90 );

               g.TranslateTransform( -x, -y );
               g.TranslateTransform( -( characterSize.Width / 2 ), -( characterSize.Height / 2 ) );

               g.DrawString( character.ToString(), font, _greenBrush, x, y );
               g.ResetTransform();
            }
         }
      }
Ejemplo n.º 6
0
        public static Image GetRotateImage(this Image img, float angle)
        {
            angle = angle % 360;//弧度转换
            double radian = angle * Math.PI / 180.0;
            double cos    = Math.Cos(radian);
            double sin    = Math.Sin(radian);
            //原图的宽和高
            int w = img.Width;
            int h = img.Height;
            int W = 80; // (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
            int H = 80; //(int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
            //目标位图
            Image dsImage = new Bitmap(W, H, img.PixelFormat);

            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage))
            {
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
                g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                //计算偏移量
                Point Offset = new Point((W - w) / 2, (H - h) / 2);
                //构造图像显示区域:让图像的中心与窗口的中心点一致
                Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
                Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
                g.TranslateTransform(center.X, center.Y);
                g.RotateTransform(360 - angle);
                //恢复图像在水平和垂直方向的平移
                g.TranslateTransform(-center.X, -center.Y);
                g.DrawImage(img, rect);
                //重至绘图的所有变换
                g.ResetTransform();
                g.Save();
            }
            return(dsImage);
        }
Ejemplo n.º 7
0
        private static Image rotateImage(Image img, float rotationAngle)
        {
            //create an empty Bitmap image
            Bitmap bmp = new Bitmap(img.Width, img.Height);

            //turn the Bitmap into a Graphics object
            System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(bmp);

            //now we set the rotation point to the center of our image
            gfx.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2);

            //now rotate the image
            gfx.RotateTransform(rotationAngle);

            gfx.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.Height / 2);

            //set the InterpolationMode to HighQualityBicubic so to ensure a high
            //quality image once it is transformed to the specified size
            gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;

            //now draw our new image onto the graphics object
            gfx.DrawImage(img, new Point(0, 0));

            //dispose of our Graphics object
            gfx.Dispose();

            //return the image
            return(bmp);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Renders a label to the map.
        /// </summary>
        /// <param name="graphics">Graphics reference</param>
        /// <param name="labelPoint">Label placement</param>
        /// <param name="offset">Offset of label in screen coordinates</param>
        /// <param name="font">Font used for rendering</param>
        /// <param name="forecolor">Font forecolor</param>
        /// <param name="backcolor">Background color</param>
        /// <param name="halo">Color of halo</param>
        /// <param name="rotation">Text rotation in degrees</param>
        /// <param name="text">Text to render</param>
        /// <param name="viewport"></param>
        public static void DrawLabel(Graphics graphics, Point labelPoint, Offset offset, Styles.Font font, Styles.Color forecolor, Styles.Brush backcolor, Styles.Pen halo, double rotation, string text, IViewport viewport, StyleContext context)
        {
            SizeF fontSize = graphics.MeasureString(text, font.ToGdi(context)); //Calculate the size of the text
            labelPoint.X += offset.X; labelPoint.Y += offset.Y; //add label offset
            if (Math.Abs(rotation) > Constants.Epsilon && !double.IsNaN(rotation))
            {
                graphics.TranslateTransform((float)labelPoint.X, (float)labelPoint.Y);
                graphics.RotateTransform((float)rotation);
                graphics.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2);
                if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent)
                    graphics.FillRectangle(backcolor.ToGdi(context), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                var path = new GraphicsPath();
                path.AddString(text, new FontFamily(font.FontFamily), (int)font.ToGdi(context).Style, font.ToGdi(context).Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                    graphics.DrawPath(halo.ToGdi(context), path);
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
            }
            else
            {
                if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent)
                    graphics.FillRectangle(backcolor.ToGdi(context), (float)labelPoint.X, (float)labelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f);

                var path = new GraphicsPath();

                //Arial hack
                path.AddString(text, new FontFamily("Arial"), (int)font.ToGdi(context).Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null);
                if (halo != null)
                    graphics.DrawPath(halo.ToGdi(context), path);
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }
Ejemplo n.º 9
0
        public System.Drawing.Size DrawToGraphics(System.Drawing.Graphics pGraphics)
        {
            System.Drawing.Size       size   = new System.Drawing.Size(0, 0);
            System.Drawing.SolidBrush pBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
            System.Drawing.Font       pFont  = new System.Drawing.Font("Times New Roman", 16, System.Drawing.FontStyle.Bold);
            SolidBrush pBackgroundBrush      = new SolidBrush(Color.FromArgb(255, 53, 53, 24));
            int        CurrentHeight         = ComponentSize.DeckSize.ProcentLabelHeight;

            {
                pGraphics.FillRectangle(pBackgroundBrush, 0, 0, 234, CurrentHeight);
                SizeF  sizeName = pGraphics.MeasureString(m_DeckName, pFont);
                double StartX   = (ComponentSize.DeckSize.FullWidht - sizeName.Width) / 2.0;
                pGraphics.DrawString(m_DeckName, pFont, pBrush, new System.Drawing.PointF((int)StartX, 3));
            }
            {
                pGraphics.FillRectangle(pBackgroundBrush, 0, CurrentHeight, 234, CurrentHeight);
                string percentStr = (m_DeckPersent * 100).ToString() + " %";
                pGraphics.DrawString(percentStr, pFont, pBrush, new System.Drawing.PointF(80, CurrentHeight + 3));
                CurrentHeight += ComponentSize.DeckSize.ProcentLabelHeight;
            }
            pGraphics.TranslateTransform(0, CurrentHeight);
            List <Hearthstone_Deck_Tracker.Hearthstone.Card> cardsList = utils.CardDictinaryToList(m_Cards);

            for (int i = 0; i < cardsList.Count; i++)
            {
                size           = utils.DrawCard(cardsList[i], m_Cards[cardsList[i]], pGraphics);
                CurrentHeight += size.Height;
                pGraphics.TranslateTransform(0, size.Height);
            }
            return(new System.Drawing.Size(size.Width, CurrentHeight));
        }
Ejemplo n.º 10
0
        public draw_image(System.Drawing.Graphics g, System.Reflection.Assembly myAssembly, String embeded_img_name, int x, int y, int width, int height, int rotation = 0, bool back_transperency = false)
        {
            Stream myStream = myAssembly.GetManifestResourceStream("test_LD." + embeded_img_name);
            Bitmap img      = new Bitmap(myStream);

            if (rotation != 0)
            {
                int moveX = img.Width / 2 + x;
                int moveY = img.Height / 2 + y;
                g.TranslateTransform(moveX, moveY);
                g.RotateTransform(rotation);
                g.TranslateTransform(-moveX, -moveY);
                if (back_transperency == false)
                {
                    g.FillRectangle(Brushes.White, x, y, width, height);
                }
                g.DrawImage(img, x, y, width, height);
                g.ResetTransform();
            }
            else
            {
                if (back_transperency == false)
                {
                    g.FillRectangle(Brushes.White, x, y, width, height);
                }
                g.DrawImage(img, x, y, width, height);
            }
        }
Ejemplo n.º 11
0
 public override void onManagedDraw(Graphics graphics)
 {
     graphics.TranslateTransform (this.CenterX, this.CenterY);
     graphics.RotateTransform (90 + this.Angle / (float)Math.PI * 180);
     graphics.TranslateTransform (-this.CenterX, -this.CenterY);
     base.onManagedDraw (graphics);
     graphics.ResetTransform ();
 }
Ejemplo n.º 12
0
		public virtual void Paint(Graphics graphics)
		{
			foreach (GraphElement element in SubElements)
			{
				graphics.TranslateTransform(element.X, element.Y);
				element.Paint(graphics);
				graphics.TranslateTransform(-element.X, -element.Y);
			}
		}
Ejemplo n.º 13
0
		public override void Draw(Graphics graphics)
		{
			if (graphics == null) return;
			CollapseShape.DrawButton(graphics);
			
			graphics.TranslateTransform(1, 1);
			CollapseShape.DrawArrow(graphics);
			graphics.TranslateTransform(0, 6);
			CollapseShape.DrawArrow(graphics);
		}
        private void DrawElement(Graphics g, Act2DMapLayoutObject.Element e)
        {
            var bitmap = file.CreateBitmapForResource(e.resourceID);
            if (bitmap == null) return;

            g.TranslateTransform(e.x, e.y);
            g.TranslateTransform(bitmap.Width * 0.5f, bitmap.Height * 0.5f);
            g.RotateTransform(e.rotate);
            g.ScaleTransform(e.scale_x, e.scale_y);
            g.TranslateTransform(-bitmap.Width * 0.5f, -bitmap.Height * 0.5f);
            g.DrawImage(bitmap, new PointF(0.0f, 0.0f));
        }
Ejemplo n.º 15
0
 public void Draw(Graphics g)
 {
     float dL = length / 2.0f;
     float dW = width / 2.0f;
     g.TranslateTransform(x + dL, y + dW);
     g.RotateTransform(angle);
     g.TranslateTransform(-dL, -dW);
     g.DrawRectangle(new Pen(Color.Black), 0, 0, length, width);
     g.TranslateTransform(dL, dW);
     g.RotateTransform(-angle);
     g.TranslateTransform(-x - dL, -y - dW);
 }
Ejemplo n.º 16
0
		private void DrawArrow(Graphics g,float dx,float dy,Color color)
		{
			int cx = 20;
			int cy = 20;
			Pen penWide   = new Pen(color,2);
			Point[] apt = {new Point(5*cx/32,3*cy/8),new Point(20*cx/32,0),new Point(20*cx/32,5*cy/8)};
			penWide.LineJoin = LineJoin.Miter;
			g.TranslateTransform(dx,dy);
			g.DrawLines(penWide,apt);
			g.TranslateTransform(-dx,-dy);

		}
Ejemplo n.º 17
0
        public static void Paint(Graphics g, Report report)
        {
            g.TranslateTransform(10, 10);
            PaintPlayer(g, report.Attacker.Village);
            g.TranslateTransform(0, 27);
            PaintTroops(g, report.Attack);

            g.TranslateTransform(0, 70);
            PaintPlayer(g, report.Defender.Village);
            g.TranslateTransform(0, 27);
            PaintTroops(g, report.Defense);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Apply the rotation
        /// </summary>
        /// <param name="p_g">Graphic object</param>
        /// <param name="p_point">Location where to draw object</param>
        /// <param name="p_bitmap">Reference to bitmap to draw on</param>
        public virtual void ApplyAlteration(Graphics p_g, Point p_point, ref Bitmap p_bitmap)
        {
            p_g.TranslateTransform((float)(p_point.X), (float)(p_point.Y));

            // Rotate desired degrees
            p_g.RotateTransform((float)rotation * -1);

            // Move the origin back to where it belongs while it is rotated
            p_g.TranslateTransform((float)(p_point.X) * -1, (float)(p_point.Y) * -1);

            rotation += angle;
            if (rotation > 360) rotation -= 360;
        }
Ejemplo n.º 19
0
        public override void Render(System.Drawing.Rectangle rectangle, System.Drawing.Graphics graphics)
        {
            GraphicsState s = graphics.Save();

            Rectangle rt = new System.Drawing.Rectangle(0, 0, 57, 88);

            graphics.TranslateTransform(-rt.Width / 2, -rt.Height / 2, MatrixOrder.Append);
            graphics.RotateTransform(20, MatrixOrder.Append);
            graphics.TranslateTransform(((rectangle.X + rectangle.Width)) / 2, ((rectangle.Y + rectangle.Height)) / 2, MatrixOrder.Append);


            graphics.FillRectangle(Brushes.White, rt);
            graphics.Restore(s);
        }
        private static Bitmap RotateImage(Bitmap bmp, float angle)
        {
            Bitmap rotatedImage = new Bitmap(bmp.Width, bmp.Height);

            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(rotatedImage))
            {
                g.TranslateTransform(bmp.Width / 2, bmp.Height / 2);
                g.RotateTransform(angle + 45);
                g.TranslateTransform(-bmp.Width / 2, -bmp.Height / 2);
                g.DrawImage(bmp, new Point(0, 0));
            }

            return(rotatedImage);
        }
Ejemplo n.º 21
0
        public static void RotateImage(Stream originalStream, string thumbnailPath, int angle)
        {
            Image originalImage = Image.FromStream(originalStream);

            angle = angle % 360;
            //弧度转换
            double radian = angle * Math.PI / 180.0;
            double cos    = Math.Cos(radian);
            double sin    = Math.Sin(radian);
            //原图的宽和高
            int w = originalImage.Width;
            int h = originalImage.Height;
            int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
            int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
            //目标位图
            Bitmap dsImage = new Bitmap(W, H);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //计算偏移量
            Point Offset = new Point((W - w) / 2, (H - h) / 2);
            //构造图像显示区域:让图像的中心与窗口的中心点一致
            Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
            Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            g.TranslateTransform(center.X, center.Y);
            g.RotateTransform(360 - angle);
            //恢复图像在水平和垂直方向的平移
            g.TranslateTransform(-center.X, -center.Y);
            g.DrawImage(originalImage, rect);
            //重至绘图的所有变换
            g.ResetTransform();
            g.Save();
            try
            {
                dsImage.Save(thumbnailPath);
            }
            catch
            {
                throw;
            }
            finally
            {
                originalImage.Dispose();
                dsImage.Dispose();
                g.Dispose();
            }
        }
Ejemplo n.º 22
0
Archivo: Star.cs Proyecto: CPutz/MyMap
 public void Draw(Graphics gr, Point center, double textSizePercentage, bool showName)
 {
     gr.TranslateTransform(center.X, center.Y);
     // center of logo is now considered (0,0)
     gr.FillPolygon(Brushes.Yellow, new Point[] { starPoints[0], starPoints[2], starPoints[4], starPoints[1], starPoints[3] }, FillMode.Winding);
     int r = (int)radius;
     //gr.DrawEllipse(Pens.Black,- r, - r, 2 * r, 2 * r);
     if (showName)
     {
         Font font = new Font("Tahoma", (float) (textSizePercentage * Radius / 500));
         SizeF sizeF = gr.MeasureString(name, font);
         gr.DrawString(name, font, Brushes.Black, new PointF(-sizeF.Width / 2, -sizeF.Height / 2));
     }
     gr.TranslateTransform(-center.X, -center.Y);
 }
Ejemplo n.º 23
0
        } // end of Crop

        /// <summary>
        /// 以逆时针方向为正方向对图像进行旋转
        /// </summary>
        /// <param name="b">位图流</param>
        /// <param name="angle">旋转角度[0, 360]</param>
        /// <returns></returns>
        public Bitmap Rotate(Bitmap b, int angle)
        {
            angle = angle % 360;

            // 弧度转化
            double radian = angle * Math.PI / 180.0;
            double cos    = Math.Cos(radian);
            double sin    = Math.Sin(radian);

            // 原图宽高
            int w = b.Width;
            int h = b.Height;

            // 新图的宽高
            int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
            int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));

            // 目标位图,即旋转后的图
            Bitmap dstImage = new Bitmap(W, H);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dstImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            // 偏移量
            Point offset = new Point((W - w) / 2, (H - h) / 2);

            // 构造图像显示区域:让图像的中心点与窗口的中心点一致
            Rectangle rect   = new Rectangle(offset.X, offset.Y, w, h);
            Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            // 以图像的中心点旋转
            g.TranslateTransform(center.X, center.Y);
            g.RotateTransform(360 - angle);

            // 恢复图像在水平和垂直方向的平移
            g.TranslateTransform(-center.X, -center.Y);

            // 绘制旋转后的结果图
            g.DrawImage(b, rect);

            // 重置绘图的所有变换
            g.ResetTransform();

            g.Save();

            return(dstImage);
        } // end of Rotate
Ejemplo n.º 24
0
        private void DrawRobot(Robot r, Graphics g)
        {
            var frame = (Math.Abs(r.Steps / (int)(0.02 * BPS)) + int.MaxValue / 2) % 8;
            g.TranslateTransform((float)r.X, (float)r.Y);
            g.RotateTransform((float)r.Angle);
            g.DrawImage(RobotImage, new Rectangle(-16, -16, 32, 32), new Rectangle(0 + 32 * frame, 0, 32, 32), GraphicsUnit.Pixel);
            g.RotateTransform((float)r.CannonAngle);
            g.DrawImage(CannonImage, new Rectangle(-7, -7, 24, 14));
            g.RotateTransform(-(float)r.CannonAngle);
            g.RotateTransform(-(float)r.Angle);

            //g.FillPolygon(Brushes.LightGray, new[] {
            //    new PointF((float)Math.Round(-15f), (float)Math.Round(-12f)),
            //    new PointF((float)Math.Round(15f), (float)Math.Round(-12f)),
            //    new PointF((float)Math.Round(15f), (float)Math.Round(-9f)),
            //    new PointF((float)Math.Round(-15f), (float)Math.Round(-9f)),
            //});
            g.FillPolygon(Brushes.Red, new[] {
                new PointF((float)Math.Round(-15f), (float)Math.Round(-12f)),
                new PointF((float)Math.Round(-15f + 30 * Math.Max(0, r.HP)), (float)Math.Round(-12f)),
                new PointF((float)Math.Round(-15f + 30 * Math.Max(0, r.HP)), (float)Math.Round(-9f)),
                new PointF((float)Math.Round(-15f), (float)Math.Round(-9f)),
            });
            //g.FillPolygon(Brushes.Blue, new[] {
            //    new PointF((float)Math.Round(-15f), (float)Math.Round(-9f)),
            //    new PointF((float)Math.Round(-15f + 30 * Math.Max(0, 1 - (double)r.FireCooldown / GameState.FIRE_COOLDOWN)), (float)Math.Round(-9f)),
            //    new PointF((float)Math.Round(-15f + 30 * Math.Max(0, 1 - (double)r.FireCooldown / GameState.FIRE_COOLDOWN)), (float)Math.Round(-7f)),
            //    new PointF((float)Math.Round(-15f), (float)Math.Round(-7f)),
            //});

            g.TranslateTransform(-(float)r.X, -(float)r.Y);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Apply the flip
        /// </summary>
        /// <param name="p_g">Graphic object</param>
        /// <param name="p_point">Location where to draw object</param>
        /// <param name="p_bitmap">Reference to bitmap to draw on</param>
        public void ApplyAlteration(Graphics p_g, Point p_point, ref Bitmap p_bitmap)
        {
            p_g.TranslateTransform((float)(p_point.X), (float)(p_point.Y));

            Matrix m = new Matrix(1,0,0,1,0,0);

            switch(flipType)
            {
            case Animation.Flip.FlipType.Horizontal:
                m = new Matrix(-1,0,0,1,0,0);
                break;
            case Animation.Flip.FlipType.Vertical:
                m = new Matrix(1,0,0,-1,0,0);
                break;
            case Animation.Flip.FlipType.Both:
                m = new Matrix(-1,0,0,-1,0,0);
                break;
            default:
                m = new Matrix(1,0,0,1,0,0);
                break;
            }

            // Rotate desired degrees
            p_g.MultiplyTransform(m);

            // Move the origin back to where it belongs while it is rotated
            p_g.TranslateTransform((float)(p_point.X) * -1, (float)(p_point.Y) * -1);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Draw- simple draw of an entire page.  Useful when printing or creating an image.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="page"></param>
        /// <param name="clipRectangle"></param>
        public void Draw(Graphics g, int page, System.Drawing.Rectangle clipRectangle, bool drawBackground, PointF pageOffset)
        {
            DpiX = g.DpiX;			 // this can change (e.g. printing graphics context)
            DpiY = g.DpiY;

            //			g.InterpolationMode = InterpolationMode.HighQualityBilinear;	// try to unfuzz charts
            g.PageUnit = GraphicsUnit.Pixel;
            g.ScaleTransform(1, 1);

            if (!pageOffset.IsEmpty)    // used when correcting for non-printable area on paper
            {
                g.TranslateTransform(pageOffset.X, pageOffset.Y);
            }

            _left = 0;
            _top = 0;
            _hScroll = 0;
            _vScroll = 0;

            RectangleF r = new RectangleF(clipRectangle.X, clipRectangle.Y,
                                            clipRectangle.Width, clipRectangle.Height);

            if (drawBackground)
                g.FillRectangle(Brushes.White, PixelsX(_left), PixelsY(_top),
                    PixelsX(_pgs.PageWidth), PixelsY(_pgs.PageHeight));

            ProcessPage(g, _pgs[page], r, false);
        }
Ejemplo n.º 27
0
        void DrawRobot(Graphics g, Point loc)
        {
            var brush = Brushes.Teal;
            g.TranslateTransform(loc.X + CellLength / 2, loc.Y + CellLength / 2);
            g.RotateTransform(robot.KnownHeading);		//We draw for straight up - a heading of zero.
            g.TranslateTransform(-CellLength / 2, -CellLength / 2);

            g.FillEllipse(brush, 1, 1, CellLength - 2, CellLength - 2);
            //Draw a rectangle in back of the robot
            g.FillRectangle(brush, 1, 1 + CellLength / 2, CellLength - 2, CellLength / 2 - 1);

            //Draw a yellow line near the front of the circle portion
            g.DrawLine(Pens.Yellow, CellLength / 3, CellLength / 4, 2 * CellLength / 3, CellLength / 4);

            g.ResetTransform();
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Ellipse shadow Hypothetically.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Paint Event Arguments</param>
        /// <param name="control">Control for implementation</param>
        public static void DrawCircularShadow(this System.Drawing.Graphics g, Color color, Color shadowColor, Rectangle rectangle)
        {
            //Color color = Color.Blue;
            //Color shadow = Color.FromArgb(255, 16, 16, 16);

            for (int i = 0; i < 8; i++)
            {
                using (SolidBrush brush = new SolidBrush(Color.FromArgb(80 - i * 10, shadowColor)))
                {
                    g.FillEllipse(brush, rectangle.X + i * 2,
                                  rectangle.Y + i, 60, 60);
                }
            }

            using (SolidBrush brush = new SolidBrush(color))
                g.FillEllipse(brush, rectangle.X, rectangle.Y, 60, 60);

            // move to the right to use the same coordinates again for the drawn shape
            g.TranslateTransform(80, 0);

            for (int i = 0; i < 8; i++)
            {
                using (Pen pen = new Pen(Color.FromArgb(80 - i * 10, shadowColor), 2.5f))
                {
                    g.DrawEllipse(pen, rectangle.X + i * 1.25f,
                                  rectangle.Y + i, 60, 60);
                }
            }
            using (Pen pen = new Pen(color))
                g.DrawEllipse(pen, rectangle.X, rectangle.Y, 60, 60);
        }
Ejemplo n.º 29
0
 public override void OnRender(Graphics g)
 {
    //g.DrawRectangle(Pen, new System.Drawing.Rectangle(LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height));
    {
       g.TranslateTransform(ToolTipPosition.X, ToolTipPosition.Y);
       var c = g.BeginContainer();
       {                 
          g.RotateTransform(Bearing - Overlay.Control.Bearing);            
          g.ScaleTransform(Scale, Scale);
          
          g.FillPolygon(Fill, Arrow);               
       }                                                                
       g.EndContainer(c);
       g.TranslateTransform(-ToolTipPosition.X, -ToolTipPosition.Y);
    }
 }
Ejemplo n.º 30
0
        /// <summary>
        /// 绘制符号
        /// </summary>
        /// <param name="g">作图对象</param>
        /// <param name="X">水平坐标</param>
        /// <param name="Y">垂直坐标</param>
        public void Draw(System.Drawing.Graphics g, float X, float Y)
        {
            ///绘制图片
            if (_symboltype == MedSymbolType.Image)
            {
                g.DrawImage(_image, X - _image.Width / 2, Y - _image.Height / 2);
            }
            ///绘制路径
            else if (_symboltype != MedSymbolType.None)
            {
                Matrix saveMatrix = g.Transform;
                g.TranslateTransform(X, Y);

                ///创建符号路径
                GraphicsPath path = MakePath(g);

                ///填充路径
                if (_brush != null)
                {
                    g.FillPath(_brush, path);
                }

                g.DrawPath(_pen, path);
                g.Transform = saveMatrix;
            }
        }
Ejemplo n.º 31
0
        protected void PaintTransparentBackground(Graphics g, Rectangle clipRect) {
            // check if we have a parent
            if (this.Parent != null) {
                // convert the clipRects coordinates from ours to our parents
                clipRect.Offset(this.Location);

                PaintEventArgs e = new PaintEventArgs(g, clipRect);
                GraphicsState state = g.Save();

                try {
                    // move the graphics object so that we are drawing in
                    // the correct place
                    g.TranslateTransform((float)-this.Location.X, (float)-this.Location.Y);

                    // draw the parents background and foreground
                    this.InvokePaintBackground(this.Parent, e);
                    this.InvokePaint(this.Parent, e);

                    return;
                } finally {
                    // reset everything back to where they were before
                    g.Restore(state);
                    clipRect.Offset(-this.Location.X, -this.Location.Y);
                }
            }

            // we don't have a parent, so fill the rect with
            // the default control color
            g.FillRectangle(SystemBrushes.Control, clipRect);
        }
Ejemplo n.º 32
0
        public void Draw(Graphics g, Player player)
        {
            if (ShootingPoints.Count > 0)
            {
                try
                {
                    g.DrawCurve(shootingPen, ShootingPoints.ToArray());
                    g.TranslateTransform(1, 0);
                    g.DrawCurve(shootingPen1, ShootingPoints.ToArray());
                    g.ResetTransform();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Shot.cs-Draw-EXCEPTION :  {0}", e.Message);
                }
                //STRELKA
                Point lastOne = (Point)ShootingPoints[ShootingPoints.Count-1];
                trianglePoints = new Point[3];

                trianglePoints[0] = new Point(lastOne.X - 2, lastOne.Y - 10);
                trianglePoints[1] = new Point(lastOne.X - 8, lastOne.Y + 2);
                trianglePoints[2] = new Point(lastOne.X + 4, lastOne.Y + 2);

                g.FillPolygon(new SolidBrush(Color.Black), trianglePoints);
                trianglePoints = new Point[3];
            }
        }
        public static System.Drawing.Graphics FromDrawable(Gdk.Drawable drawable)
        {
            IntPtr x_drawable;
            int    x_off = 0, y_off = 0;


            if (drawable is Gdk.Window)
            {
                ((Gdk.Window)drawable).GetInternalPaintInfo(out drawable, out x_off, out y_off);
            }
            x_drawable = drawable.Handle;

            IntPtr display = gdk_x11_drawable_get_xdisplay(x_drawable);

            Type       graphics = typeof(System.Drawing.Graphics);
            MethodInfo mi       = graphics.GetMethod("FromXDrawable", BindingFlags.Static | BindingFlags.NonPublic);

            if (mi == null)
            {
                throw new NotImplementedException("In this implementation I can not get a graphics from a drawable");
            }
            object [] args = new object [2] {
                (IntPtr)gdk_x11_drawable_get_xid(drawable.Handle), (IntPtr)display
            };
            object r = mi.Invoke(null, args);

            System.Drawing.Graphics g = (System.Drawing.Graphics)r;

            g.TranslateTransform(-x_off, -y_off);

            return(g);
        }
Ejemplo n.º 34
0
		public void Draw (Graphics graphics, Route route, bool atEnd)
		{
			if (graphics == null) return;
			if (route == null) return;
			GraphicsState state = graphics.Save();
			float direction = 0;
			PointF pos = default(PointF);
			if (atEnd)
			{
				pos = route.GetEndPoint();
				direction = ConvertDirection(route.GetEndDirection());
			}
			else
			{
				pos = route.GetStartPoint();
				direction = ConvertDirection(route.GetStartDirection());
			}
			
			// In matrix math, the correct way is to put rotation BEFORE
			// translation. However, the simple transformation maethods of
			// GDI+ works in "Prepend" mode, which reverses the order of
			// operations.
			graphics.TranslateTransform(pos.X, pos.Y);
			graphics.RotateTransform(direction);
			
			Paint(graphics);
			graphics.Restore(state);
		}
Ejemplo n.º 35
0
 public void RedrawDeck()
 {
     if (m_ShowDeck != null)
     {
         System.Drawing.Graphics pGraphics = this.CreateGraphics();
         m_ShowDeck.DrawToGraphics(pGraphics);
     }
     else if (m_DeckList != null)
     {
         System.Drawing.Graphics pGraphics = this.CreateGraphics();
         pGraphics.Clear(Color.Honeydew);
         int count    = m_DeckList.Count;
         int CurrentX = 0;
         for (int i = 0; i < count; i++)
         {
             kernal.PlayedDeck deck = m_DeckList[i];
             Size deckSize          = deck.GetSize();
             var  saveState         = pGraphics.Save();
             pGraphics.TranslateTransform(CurrentX, 0);
             deck.DrawToGraphics(pGraphics);
             pGraphics.Restore(saveState);
             CurrentX += deckSize.Width;
         }
     }
 }
Ejemplo n.º 36
0
 public EdgeDisplay(LedEdge edge, LedSubarea pSub)
 {
     this.ledEdge       = edge;
     this.ledSub        = pSub;
     this.subSize       = pSub.Size;
     this.circular      = (this.subSize.Width + this.subSize.Height) * 2;
     this.circularCount = 0m;
     lock (LedGlobal.LedEdgeList[edge.Index])
     {
         if (this.ledEdge.Enabled)
         {
             this.AlphaBitmap = new System.Drawing.Bitmap((this.subSize.Width + this.subSize.Height) * 2, edge.Height);
             this.EdgeBitmap  = new System.Drawing.Bitmap((this.subSize.Width + this.subSize.Height) * 2, edge.Height);
             System.Drawing.Graphics     graphics = System.Drawing.Graphics.FromImage(this.EdgeBitmap);
             System.Drawing.TextureBrush brush    = new System.Drawing.TextureBrush(LedGlobal.LedEdgeList[edge.Index]);
             graphics.FillRectangle(brush, new System.Drawing.Rectangle(0, 0, this.EdgeBitmap.Width, this.EdgeBitmap.Height));
             if (this.ledEdge.Mode != LedEdgeMode.Clockwise && this.ledEdge.Mode == LedEdgeMode.CounterClockwise)
             {
                 this.EdgeBitmap = this.SetCornerAlpha(this.EdgeBitmap);
             }
             this.StaticBitmap = new System.Drawing.Bitmap(this.subSize.Width, this.subSize.Height);
             System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(this.StaticBitmap);
             graphics2.DrawImage(this.EdgeBitmap, new System.Drawing.Point(0, 0));
             graphics2.TranslateTransform(0f, 0f);
             graphics2.RotateTransform(90f);
             graphics2.DrawImage(this.EdgeBitmap, new System.Drawing.Rectangle(0, -this.subSize.Width, this.subSize.Height, this.ledEdge.Height), new System.Drawing.Rectangle(this.subSize.Width, -1, this.subSize.Height, this.ledEdge.Height), System.Drawing.GraphicsUnit.Pixel);
             graphics2.DrawImage(this.EdgeBitmap, new System.Drawing.Rectangle(0, -this.subSize.Width, this.subSize.Height, this.ledEdge.Height), new System.Drawing.Rectangle(this.subSize.Width, 0, this.subSize.Height, this.ledEdge.Height), System.Drawing.GraphicsUnit.Pixel);
             graphics2.RotateTransform(90f);
             graphics2.DrawImage(this.EdgeBitmap, new System.Drawing.Rectangle(-this.subSize.Width, -this.subSize.Height, this.subSize.Width, this.ledEdge.Height), new System.Drawing.Rectangle(this.subSize.Width + this.subSize.Height, -1, this.subSize.Width, this.ledEdge.Height), System.Drawing.GraphicsUnit.Pixel);
             graphics2.RotateTransform(90f);
             graphics2.DrawImage(this.EdgeBitmap, new System.Drawing.Rectangle(-this.subSize.Height, 0, this.subSize.Height, this.ledEdge.Height), new System.Drawing.Rectangle(this.subSize.Width * 2 + this.subSize.Height, 0, this.subSize.Height, this.ledEdge.Height), System.Drawing.GraphicsUnit.Pixel);
         }
     }
 }
Ejemplo n.º 37
0
 public void draw(System.Drawing.Graphics g)
 {
     g.TranslateTransform(this.x, this.y);
     g.RotateTransform(rotation);
     g.DrawImage(canon, (0 - canon.Width / 2), (0 - canon.Height / 2), canon.Width, canon.Height);
     g.ResetTransform();
 }
Ejemplo n.º 38
0
        public override void OnRender(Graphics g)
        {
            #if !PocketPC
             if(!Bearing.HasValue)
             {
            g.DrawImageUnscaled(Resources.shadow50, LocalPosition.X, LocalPosition.Y);
             }
             g.TranslateTransform(ToolTipPosition.X, ToolTipPosition.Y);

             if(Bearing.HasValue)
             {
            g.RotateTransform(Bearing.Value - Overlay.Control.Bearing);
            g.FillPolygon(Brushes.Lime, Arrow);
             }

             g.ResetTransform();

             if(!Bearing.HasValue)
             {
            g.DrawImageUnscaled(Resources.bigMarkerGreen, LocalPosition.X, LocalPosition.Y);
             }
            #else
            DrawImageUnscaled(g, Resources.shadow50, LocalPosition.X, LocalPosition.Y);
            DrawImageUnscaled(g, Resources.marker, LocalPosition.X, LocalPosition.Y);
            #endif
        }
            /// <summary>
            /// Initializes a new instance of the <see cref="PixelZoom"/> class.
            /// </summary>
            /// <param name="parent">The parent.</param>
            public PixelZoom(ZeroitEyeDropper parent)
            {
                this.parent          = parent;
                this.ShowInTaskbar   = false;
                this.TopMost         = true;
                this.FormBorderStyle = FormBorderStyle.None;
                this.StartPosition   = FormStartPosition.Manual;
                //We intentionally set the bounds after showing the form.
                //This bypasses a bug in the Form class when setting the
                //bounds internally before calling the Show() method.
                this.Show();
                setBounds();

                //Paint the bounds as a rounded rectangle...
                System.Drawing.Graphics g = this.CreateGraphics();
                g.SmoothingMode = SmoothingMode.AntiAlias;
                GraphicsPath gpArea = this.BuildRoundedRectangle(new Rectangle(shadow, shadow, this.Width - shadow, this.Height - shadow), 20);

                using (SolidBrush sb = new SolidBrush(Color.FromArgb(150, Color.Black)))
                { g.FillPath(sb, gpArea); }
                g.TranslateTransform(-shadow, -shadow);
                g.FillPath(Brushes.WhiteSmoke, gpArea);
                g.DrawPath(Pens.Black, gpArea);
                g.Dispose();
                gpArea.Dispose();
            }
Ejemplo n.º 40
0
        public override void DrawRect(System.Drawing.RectangleF dirtyRect)
        {
            //			var gc = NSGraphicsContext.FromGraphicsPort(
            //				NSGraphicsContext.CurrentContext.GraphicsPort.Handle,true);

            //			var gc = NSGraphicsContext.CurrentContext;
            //
            //			var g = new Graphics(gc.GraphicsPort);
            var g = new Graphics();

            // NSView does not have a background color so we just use Clear to white here
            g.Clear(Color.White);

            //RectangleF ClientRectangle = this.Bounds;
            RectangleF ClientRectangle = dirtyRect;

            // Following codes draw a line from (0, 0) to (1, 1) in unit of inch:
            /*g.PageUnit = GraphicsUnit.Inch;
            Pen blackPen = new Pen(Color.Black, 1/g.DpiX);
            g.DrawLine(blackPen, 0, 0, 1, 1);*/

            // Following code shifts the origin to the center of
            // client area, and then draw a line from (0,0) to (1, 1) inch:
            g.PageUnit = GraphicsUnit.Inch;
            g.TranslateTransform((ClientRectangle.Width / g.DpiX) / 2,
                                 (ClientRectangle.Height / g.DpiY) / 2);
            Pen greenPen = new Pen(Color.Green, 1 /  g.DpiX);
            g.DrawLine(greenPen, 0, 0, 1, 1);

            g.Dispose ();
        }
Ejemplo n.º 41
0
        public static void DrawFocusedItemMark(System.Drawing.Graphics g, float x, float y, bool drawWhiteBounds = false)
        {
            if (focusedItemMark == null)
            {
                var b = FocusedItemMarkBounds;
                focusedItemMark = new GraphicsPath();
                focusedItemMark.AddPolygon(new []
                {
                    new PointF(0, b.Top),
                    new PointF(b.Width - 1, 0),
                    new PointF(0, b.Bottom),
                });
                focusedItemMarkBorder = new GraphicsPath();
                focusedItemMarkBorder.AddPolygon(new[]
                {
                    new PointF(0, b.Top - 1.5f),
                    new PointF(b.Width, 0),
                    new PointF(0, b.Bottom + 1.5f),
                });
            }

            GraphicsState state = g.Save();

            g.TranslateTransform(x, y);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillPath(System.Drawing.Brushes.Blue, focusedItemMark);
            if (drawWhiteBounds)
            {
                g.DrawPath(System.Drawing.Pens.White, focusedItemMarkBorder);
            }
            g.Restore(state);
        }
Ejemplo n.º 42
0
        public static Image LoadImage(string text)
        {
            System.Drawing.Bitmap   bmp     = new System.Drawing.Bitmap(1, 1);
            System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(bmp);
            System.Drawing.Font     font    = new System.Drawing.Font("Arial", 11, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic);
            int width  = Convert.ToInt32(graphic.MeasureString(text, font).Width);
            int height = Convert.ToInt32(graphic.MeasureString(text, font).Height);

            bmp     = new System.Drawing.Bitmap(height, width);
            graphic = System.Drawing.Graphics.FromImage(bmp);
            graphic.Clear(System.Drawing.Color.White);
            graphic.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            graphic.TranslateTransform(0, width);
            graphic.RotateTransform(270);
            graphic.DrawString(text, font, new System.Drawing.SolidBrush(System.Drawing.Color.Fuchsia), 0, 0);
            graphic.Flush();

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            // return ms.ToArray();

            Image returnImage = Image.FromStream(ms);

            return(returnImage);
        }
        /// <summary>
        /// 图片旋转子函数
        /// </summary>
        /// <param name="b">源图片</param>
        /// <param name="angle">角度</param>
        /// <returns>(无返回值)</returns>
            public Image RotateImg(Image b, int angle)
            
        {
               angle = angle % 360;
               //弧度转换
               double radian = angle * Math.PI / 180.0;
               double cos    = Math.Cos(radian);
               double sin    = Math.Sin(radian);
               //原图的宽和高
               int w = b.Width;
               int h = b.Height;
               int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
               int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
               //目标位图
               Bitmap dsImage            = new Bitmap(W, H);
               System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
               g.InterpolationMode       = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
               g.SmoothingMode           = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
               //计算偏移量
               Point Offset = new Point((W - w) / 2, (H - h) / 2);
               //构造图像显示区域:让图像的中心与窗口的中心点一致
               Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
               Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
               g.TranslateTransform(center.X, center.Y);

               g.RotateTransform(360 - angle);

               //恢复图像在水平和垂直方向的平移
               g.TranslateTransform(-center.X, -center.Y);

               g.DrawImage(b, rect);

               //重至绘图的所有变换
               g.ResetTransform();

               g.Save();

               g.Dispose();

               //显示旋转后的图片
            b.Dispose();

            pictureBox4.Image = dsImage;
            return(dsImage);

              
        }
Ejemplo n.º 44
0
        public Image RotateImg(Image b, float angle)
        {
            //Bitmap bmpsource=new Bitmap(img);
            //Bitmap bmpsrc=new Bitmap(bmpsource.Width,bmpsource.Height);
            //Rectangle rect = new Rectangle(0, 0, bmpsource.Width, bmpsource.Height);
            //Graphics g = Graphics.FromImage(bmpsource);
            //g.RotateTransform(angle);
            //g.DrawImage(bmpsrc,rect);
            //g.Dispose();
            ////MessageBox.Show("1");
            //return bmpsrc;
            angle = angle % 360;
            //弧度转换
            double radian = angle * Math.PI / 180.0;
            double cos    = Math.Cos(radian);
            double sin    = Math.Sin(radian);
            //原图的宽和高
            int w = b.Width;
            int h = b.Height;
            int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
            int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
            //目标位图
            Bitmap dsImage = new Bitmap(W, H);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //计算偏移量
            Point Offset = new Point((W - w) / 2, (H - h) / 2);
            //构造图像显示区域:让图像的中心与窗口的中心点一致
            Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
            Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            g.TranslateTransform(center.X, center.Y);
            g.RotateTransform(360 - angle);
            //恢复图像在水平和垂直方向的平移
            g.TranslateTransform(-center.X, -center.Y);
            g.DrawImage(b, rect);
            //重至绘图的所有变换
            g.ResetTransform();
            g.Save();
            g.Dispose();
            //保存旋转后的图片
            b.Dispose();
            //dsImage.Save("FocusPoint.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            return(dsImage);
        }
Ejemplo n.º 45
0
 private void ApplyTransform(Graphics g)
 {
     scale = Math.Min(ClientRectangle.Width / clientSize,
     ClientRectangle.Height / clientSize);
     if (scale == 0f) return;
     g.ScaleTransform(scale, scale);
     g.TranslateTransform(offset, offset);
 }
        public IDisposable ApplyOffset(float dx, float dy)
        {
            var graphicsContainer = m_Graphics.BeginContainer();

            m_Graphics.TranslateTransform(dx, dy);

            return(new DoOnDispose(() => m_Graphics.EndContainer(graphicsContainer)));
        }
Ejemplo n.º 47
0
    private Bitmap RotateImage(Bitmap bmp, float angle)
    {
        Bitmap rotatedImage = new Bitmap(bmp.Width, bmp.Height);

        using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(rotatedImage)) {
            // Set the rotation point to the center in the matrix
            g.TranslateTransform(bmp.Width / 2, bmp.Height / 2);
            // Rotate
            g.RotateTransform(angle);
            // Restore rotation point in the matrix
            g.TranslateTransform(-bmp.Width / 2, -bmp.Height / 2);
            // Draw the image on the bitmap
            g.DrawImage(bmp, new Point(0, 0));
        }

        return(rotatedImage);
    }
Ejemplo n.º 48
0
        public void Draw(Graphics g)
        {
            g.ResetTransform();

            var rnd = new Random();
            g.TranslateTransform((float)rnd.NextDouble() * g.VisibleClipBounds.Width, (float)rnd.NextDouble() * g.VisibleClipBounds.Height / 2f);
            g.DrawString(text, new Font("Comic Sans", 14), new SolidBrush(Color.Black), 0,0);
        }
		public override void Draw(Graphics graphics)
		{
			if (graphics == null) return;
			GraphicsState state = graphics.Save();
			CollapseExpandShape.DrawButton(graphics);
			
			if (collapsed)
			{
				graphics.TranslateTransform(0, 21);
				graphics.ScaleTransform(1, -1);
			}

			CollapseExpandShape.DrawArrow(graphics);
			graphics.TranslateTransform(0, 6);
			CollapseExpandShape.DrawArrow(graphics);
			graphics.Restore(state);
		}
Ejemplo n.º 50
0
 public override void Draw(Graphics gr)
 {
     gr.TranslateTransform(location.X, location.Y);
     gr.DrawPath(pen, path);
     if (!string.IsNullOrEmpty(text))
         gr.DrawString(text, SystemFonts.DefaultFont, Brushes.Black, textRect, StringFormat.GenericDefault);
     gr.ResetTransform();
 }
Ejemplo n.º 51
0
 public override void OnRender(Graphics g)
 {
     Matrix temp = g.Transform;
     g.TranslateTransform(LocalPosition.X, LocalPosition.Y);
     Image pic = global::MultiWiiWinGUI.Properties.Resources.home;
     g.DrawImageUnscaled(pic, pic.Width / -2 - 7, -pic.Height-14);
     g.Transform = temp;
 }
Ejemplo n.º 52
0
            public void Draw(Graphics g)
            {
                //Location corresponds to the center of this image...
                var copyt = g.Transform;

                g.TranslateTransform(Location.X, Location.Y);
                double useangle = (float)(Angle * (180d / Math.PI));
                Debug.Print("useangle:" + useangle);
                g.RotateTransform((float)(useangle));

                g.TranslateTransform((float)-DrawImage.Width / 2, (float)-DrawImage.Height / 2);

                //draw the image at 0,0...
                g.DrawImage(DrawImage, 0, 0,DrawSize.Width,DrawSize.Height);
                //reset the transform.
                g.Transform = copyt;
            }
Ejemplo n.º 53
0
            public override void OnRender(Graphics g)
            {
                double width = (Overlay.Control.MapProvider.Projection.GetDistance(Overlay.Control.FromLocalToLatLng(0, 0), Overlay.Control.FromLocalToLatLng(Overlay.Control.Width, 0)) * 1000.0);
                double height = (Overlay.Control.MapProvider.Projection.GetDistance(Overlay.Control.FromLocalToLatLng(0, 0), Overlay.Control.FromLocalToLatLng(Overlay.Control.Height, 0)) * 1000.0);
                double m2pixelwidth = Overlay.Control.Width / width;
                double m2pixelheight = Overlay.Control.Height / height;


                Matrix temp = g.Transform;
                g.TranslateTransform(LocalPosition.X + RectHeight, LocalPosition.Y + RectWidth);
                g.RotateTransform(-Overlay.Control.Bearing);

                
                base.OnRender(g);
                if (RectHeight == 0 || Overlay.Control == null)
                    return;

                // if we have drawn it, then keep that color
                if (!initcolor.HasValue)
                    Color = Color.White;

                //wprad = 300;

                // undo autochange in mouse over
                // if (Pen.Color == Color.Blue)
                // Pen.Color = Color.White;
                

                //GPoint loc = new GPoint((int)(LocalPosition.X - (m2pixelwidth * RectWidth * 2)), LocalPosition.Y);// MainMap.FromLatLngToLocal(wpradposition);
                GPoint loc = new GPoint((int)(LocalPosition.X - (m2pixelwidth * RectWidth)), (int)(LocalPosition.Y - (m2pixelheight * RectHeight)));// MainMap.FromLatLngToLocal(wpradposition);

                double direction = LandingDirection;

                //mine
                int x = Offset.X - (int)(Math.Abs(loc.X - (int)LocalPosition.X) / 2);
                int y = Offset.Y - (int)(Math.Abs(loc.Y - (int)LocalPosition.Y) / 2);
                int widtharc = (int)Math.Abs(loc.X - LocalPosition.X);
                int heightarc = (int)Math.Abs(loc.Y - LocalPosition.Y);
                
                if (widtharc > 0)
                {
                    try
                    {
                        g.RotateTransform((int)LandingDirection);
                    }
                    catch { }

                    //draw circle
                    //g.DrawArc(Pen, new System.Drawing.Rectangle(x, y, widtharc, heightarc), 0, 360);
                    //g.FillPie(new SolidBrush(Color.FromArgb(25, FillColor)), x, y, widtharc, heightarc, 0, 360);

                    g.DrawRectangle(Pen, x, y, RectWidth * (int)m2pixelwidth, RectHeight * (int)m2pixelheight);
                    g.FillRectangle(new SolidBrush(Color.FromArgb(25, FillColor)), x, y, RectWidth * (int)m2pixelwidth, RectHeight * (int)m2pixelheight);

                    g.Transform = temp;
                                   
                }
            }
Ejemplo n.º 54
0
        /// <summary>
        /// 画图方法
        /// </summary>
        /// <param name="g"></param>
        public override void Draw(System.Drawing.Graphics g)
        {
            base.Draw(g);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Pen pen = new Pen(base.Color, base.PenWidth);

            Rectangle rect = DrawRectanlge.GetNormalizedRectangle(base.rectangle);
            int       x    = rect.X;
            int       y    = rect.Y;
            float     d    = (float)rect.Width / 6;
            float     b    = (float)rect.Height / 6;

            g.TranslateTransform(x + 3 * d, y + 3 * b);
            g.RotateTransform(Angle);
            g.TranslateTransform(-x - 3 * d, -y - 3 * b);

            g.DrawLine(pen, new PointF(x + 0 * d, y + 3 * b), new PointF(x + 1 * d, y + 3 * b));
            g.DrawLine(pen, new PointF(x + 1 * d, y + 2 * b), new PointF(x + 1 * d, y + 4 * b));
            g.DrawLine(pen, new PointF(x + 1 * d, y + 2 * b), new PointF(x + 5 * d, y + 2 * b));
            g.DrawLine(pen, new PointF(x + 1 * d, y + 4 * b), new PointF(x + 5 * d, y + 4 * b));
            g.DrawLine(pen, new PointF(x + 5 * d, y + 2 * b), new PointF(x + 5 * d, y + 4 * b));
            g.DrawLine(pen, new PointF(x + 5 * d, y + 3 * b), new PointF(x + 6 * d, y + 3 * b));
            pen.Dispose();
            //需要学生填写
            //DrawName(g);

            Pen   pen1 = new Pen(Color.Red, 1);
            Point p;

            switch (Node)
            {
            case 1:
                p = GetNode(1);
                g.DrawArc(pen1, new RectangleF(p.X - 5, p.Y - 5, 10, 10), 0, 360);
                break;

            case 2:
                p = GetNode(2);
                g.DrawArc(pen1, new RectangleF(p.X - 5, p.Y - 5, 10, 10), 0, 360);
                break;
            }
            pen1.Dispose();
        }
Ejemplo n.º 55
0
 /// <summary>
 /// 以逆时针为方向对图像进行旋转
 /// </summary>
 /// <param name="b">位图流</param>
 /// <param name="angle">旋转角度[0,360](前台给的)</param>
 /// <param name="pathFile">保存后文件的绝对路径</param>
 /// <returns></returns>
 public static bool Rotate(Bitmap b, int angle, string pathFile)
 {
     try
     {
         angle = angle % 360;
         //弧度转换
         double radian = angle * Math.PI / 180.0;
         double cos    = Math.Cos(radian);
         double sin    = Math.Sin(radian);
         //原图的宽和高
         int w = b.Width;
         int h = b.Height;
         int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
         int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
         //目标位图
         Bitmap dsImage            = new Bitmap(W, H);
         System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
         g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
         g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
         //计算偏移量
         Point Offset = new Point((W - w) / 2, (H - h) / 2);
         //构造图像显示区域:让图像的中心与窗口的中心点一致
         Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
         Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
         g.TranslateTransform(center.X, center.Y);
         g.RotateTransform(360 - angle);
         //恢复图像在水平和垂直方向的平移
         g.TranslateTransform(-center.X, -center.Y);
         g.DrawImage(b, rect);
         //重至绘图的所有变换
         g.ResetTransform();
         g.Save();
         g.Dispose();
         b.Dispose();
         dsImage.Save(pathFile, System.Drawing.Imaging.ImageFormat.Jpeg);
         return(true);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message, ex);
     }
 }
Ejemplo n.º 56
0
        private static void DrawLine(System.Drawing.Graphics g, PointF startingPoint, float size, float length, float rotation)
        {
            var point = new PointF(2.0f * startingPoint.X, 2.0f * startingPoint.Y);

            length *= 2.0f;
            size   *= 0.6f;

            g.TranslateTransform(point.X, point.Y, MatrixOrder.Prepend);
            g.RotateTransform(-rotation, MatrixOrder.Prepend);
            g.FillRectangle(Brushes.Black, -size / 2.0f, -length, size, length);
        }
Ejemplo n.º 57
0
        private void PaintTriangle(System.Drawing.Graphics g)
        {
            System.Drawing.Pen myPen;
            myPen           = new System.Drawing.Pen(_color);
            myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;

            //get suitable triangle dimensions
            double stepSize = 5;
            double gHeight  = this.Height - stepSize; //start out from height or depth
            double gWidth   = gHeight * _sideslope * 2.0;

            do
            {
                if (gWidth > this.Width)
                {
                    gHeight -= stepSize;
                    gWidth   = gHeight * _sideslope * 2.0;
                }
                else
                {
                    break;
                }
            } while (true);

            int xPt, yPt;

            xPt = (this.Width - (int)gWidth) / 2;
            yPt = (this.Height - (int)gHeight) / 2;

            float xPtMid = (float)(xPt + gWidth / 2);
            float yPtMid = (float)(yPt + gHeight);

            g.DrawLine(myPen, (float)xPt, (float)yPt, xPtMid, yPtMid);
            g.DrawLine(myPen, (float)(xPt + gWidth), (float)yPt, xPtMid, yPtMid);

            myPen.Color     = Color.Black;
            myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
            //g.DrawLine(myPen, xPt, yPt, xPt + (int)gWidth, yPt);
            g.DrawLine(myPen, xPt + (int)(gWidth / 2), yPt, xPt + (int)(gWidth / 2), yPt + (int)gHeight);

            string     sSideSlope = _sideslope.ToString() + " (Side Slope H:V)";
            string     sDepth     = _depth.ToString() + " (Max. Depth)";
            Font       lblFont    = new Font(System.Drawing.FontFamily.GenericSerif, 9);
            SolidBrush lblBrush   = new SolidBrush(Color.Black);

            g.DrawString(sDepth, lblFont, lblBrush, (float)(xPt + gWidth / 2 + 1), (float)(yPt + gHeight / 2));
            float lRotateAng = (float)(Math.Atan2(1.0d, _sideslope) * (180 / Math.PI));

            g.TranslateTransform((float)(xPt + gWidth / 8 + 1), (float)(yPt + gWidth / 8 / 3 - 1));
            g.RotateTransform(lRotateAng);
            //g.DrawString(sSideSlope, lblFont, lblBrush, (float)(xPt + gWidth / 8), (float)(yPt + gWidth/8/3));
            g.DrawString(sSideSlope, lblFont, lblBrush, this.DisplayRectangle);
            g.ResetTransform();
        }
Ejemplo n.º 58
0
        /*                          Implementation
         *  private void button1_Click(object sender, EventArgs e)
         *  {
         *      using (Graphics G = this.CreateGraphics())
         *          drawShadow(G, Color.Black, getRectPath(new Rectangle(111, 111, 222, 222)), 17);
         *  }
         *
         */
        #endregion

        /// <summary>
        /// Draw Shadow
        /// </summary>
        /// <param name="G">Graphics class to use</param>
        /// <param name="c">Color of the shadow</param>
        /// <param name="GP">Graphics Path or Path of the shadow</param>
        /// <param name="d">Integer to represent index of a color.</param>
        /// <param name="control">Control to implement the shadow.</param>
        public static void DrawShadow(this System.Drawing.Graphics G, Color c, GraphicsPath GP, int d, Control control)
        {
            Color[] colors = getColorVector(c, control.BackColor, d).ToArray();
            for (int i = 0; i < d; i++)
            {
                G.TranslateTransform(1f, 0.75f);             // <== shadow vector!
                using (Pen pen = new Pen(colors[i], 1.75f))  // <== pen width (*)
                    G.DrawPath(pen, GP);
            }
            G.ResetTransform();
        }
Ejemplo n.º 59
0
 public void TranslateTransform(float x, float y)
 {
     if (isD3D)
     {
         d3d.TranslateTransform(x, y);
     }
     else
     {
         gdi.TranslateTransform(x, y);
     }
 }
Ejemplo n.º 60
0
        /// <summary>
        /// Renders a label to the map.
        /// </summary>
        /// <param name="g">Graphics reference</param>
        /// <param name="LabelPoint">Label placement</param>
        /// <param name="Offset">Offset of label in screen coordinates</param>
        /// <param name="font">Font used for rendering</param>
        /// <param name="forecolor">Font forecolor</param>
        /// <param name="backcolor">Background color</param>
        /// <param name="halo">Color of halo</param>
        /// <param name="rotation">Text rotation in degrees</param>
        /// <param name="text">Text to render</param>
        /// <param name="map">Map reference</param>
        public static void DrawLabel(System.Drawing.Graphics g, System.Drawing.PointF LabelPoint, System.Drawing.PointF Offset, System.Drawing.Font font, System.Drawing.Color forecolor, System.Drawing.Brush backcolor, System.Drawing.Pen halo, float rotation, string text, SharpMap.Map map)
        {
            System.Drawing.SizeF fontSize = g.MeasureString(text, font);    //Calculate the size of the text
            LabelPoint.X += Offset.X; LabelPoint.Y += Offset.Y;             //add label offset
            if (rotation != 0 && rotation != float.NaN)
            {
                g.TranslateTransform(LabelPoint.X, LabelPoint.Y);
                g.RotateTransform(rotation);
                g.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2);
                if (backcolor != null && backcolor != System.Drawing.Brushes.Transparent)
                {
                    g.FillRectangle(backcolor, 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                }
                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                path.AddString(text, font.FontFamily, (int)font.Style, font.Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                {
                    g.DrawPath(halo, path);
                }
                g.FillPath(new System.Drawing.SolidBrush(forecolor), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
                g.Transform = map.MapTransform;
            }
            else
            {
                if (backcolor != null && backcolor != System.Drawing.Brushes.Transparent)
                {
                    g.FillRectangle(backcolor, LabelPoint.X, LabelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f);
                }

                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

                path.AddString(text, font.FontFamily, (int)font.Style, font.Size, LabelPoint, null);
                if (halo != null)
                {
                    g.DrawPath(halo, path);
                }
                g.FillPath(new System.Drawing.SolidBrush(forecolor), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }