Example #1
0
        public void DrawPaths(IEnumerable <Path> paths)
        {
            foreach (var path in paths)
            {
                var graphicsPath = new GraphicsPath();

                foreach (var pathSection in path.Segments)
                {
                    pathSection.Switch(
                        p => graphicsPath.AddLine(p, p),
                        l => graphicsPath.AddLine(l.FromPoint, l.ToPoint),
                        a => graphicsPath.AddArc(a.BoundingEllipse, a.StartAngle, a.SweepAngle));
                }

                if (path.Closed || path.Image != null)
                {
                    graphicsPath.CloseFigure();
                }

                if (path.Image != null)
                {
                    var bitmap = new Bitmap(path.Image.Data);
                    var brush  = new TextureBrush(bitmap, WrapMode.Clamp);
                    brush.ScaleTransform(path.Image.Rectangle.Width / bitmap.Width, path.Image.Rectangle.Height / bitmap.Height);
                    brush.TranslateTransform(path.Image.Rectangle.Left, path.Image.Rectangle.Top, MatrixOrder.Append);

                    graphics.FillPath(brush, graphicsPath);
                }

                graphics.DrawPath(pen, graphicsPath);
            }
        }
Example #2
0
        public void ScaleTransform_Invoke_SetsTransformToExpected(Matrix originalTransform, float scaleX, float scaleY, MatrixOrder matrixOrder)
        {
            try
            {
                using (var image = new Bitmap(10, 10))
                    using (var brush = new TextureBrush(image))
                        using (Matrix expected = originalTransform.Clone())
                        {
                            expected.Scale(scaleX, scaleY, matrixOrder);
                            brush.Transform = originalTransform;

                            if (matrixOrder == MatrixOrder.Prepend)
                            {
                                TextureBrush clone = (TextureBrush)brush.Clone();
                                clone.ScaleTransform(scaleX, scaleY);
                                Assert.Equal(expected, clone.Transform);
                            }

                            brush.ScaleTransform(scaleX, scaleY, matrixOrder);
                            Assert.Equal(expected, brush.Transform);
                        }
            }
            finally
            {
                originalTransform.Dispose();
            }
        }
        private void editQuality_Paint(object sender, PaintEventArgs e)
        {
            if (hsComboBox2.SelectedIndex > 0)
            {
                HatchStyle hs = (HatchStyle)Enum.Parse(typeof(HatchStyle), hsComboBox2.SelectedItem.ToString(), true);

                using (HatchBrush hbr2 = new HatchBrush(hs, Color.Black, Color.White))
                {
                    using (TextureBrush tbr = c.TBrush(hbr2))
                    {
                        tbr.ScaleTransform(2.50F, 2.50F);
                        e.Graphics.FillRectangle(tbr, new Rectangle(pictureBox2.Location, pictureBox2.Size));
                    }
                }
            }
            if (hsComboBox3.SelectedIndex > 0)
            {
                HatchStyle hs = (HatchStyle)Enum.Parse(typeof(HatchStyle), hsComboBox3.SelectedItem.ToString(), true);

                using (HatchBrush hbr2 = new HatchBrush(hs, Color.Black, Color.White))
                {
                    using (TextureBrush tbr = c.TBrush(hbr2))
                    {
                        tbr.ScaleTransform(2.50F, 2.50F);
                        e.Graphics.FillRectangle(tbr, new Rectangle(pictureBox1.Location, pictureBox1.Size));
                    }
                }
            }
        }
 private void label1_Paint(object sender, PaintEventArgs e)
 {
     if (this.strfilename.Trim() == "")
     {
         return;
     }
     try
     {
         Bitmap       mybitmap = new Bitmap(strfilename);
         Graphics     g        = e.Graphics;
         TextureBrush mybrush  = new TextureBrush(mybitmap);
         float        x        = (float)(numericUpDownS1.Value / 100);
         float        y        = (float)(numericUpDownS2.Value / 100);
         mybrush.ScaleTransform(x, y);
         g.FillRectangle(mybrush, 0, 0, ClientRectangle.Width, ClientRectangle.Height);
         float r = (float)(numericUpDownR1.Value);
         mybrush.RotateTransform(r);
         g.FillRectangle(mybrush, 0, 0, ClientRectangle.Width, ClientRectangle.Height);
         float tx = (float)(numericUpDownT1.Value);
         float ty = (float)(numericUpDownT2.Value);
         mybrush.TranslateTransform(tx, ty);
         g.FillRectangle(mybrush, 0, 0, ClientRectangle.Width, ClientRectangle.Height);
     }
     catch (Exception Err)
     {
         MessageBox.Show("Open File Error. ", "Informatin .", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #5
0
        private Bitmap GetHeaderPic(Stream stream)
        {
            Image headerPic = null;

            if (stream == null)
            {
                //测试使用
                headerPic = Image.FromFile("Style/headerPic.jpg");
            }
            else
            {
                headerPic = Image.FromStream(stream);
            }
            var bmap = new Bitmap(40, 40);

            using (var g = Graphics.FromImage(bmap))
            {
                Rectangle rect4   = new Rectangle(0, 0, 132, 132);
                Rectangle rectImg = new Rectangle(0, 0, 40, 40);
                using (TextureBrush br = new TextureBrush(headerPic, System.Drawing.Drawing2D.WrapMode.Clamp, rect4))
                {
                    br.ScaleTransform(rectImg.Width / (float)rect4.Width, rectImg.Height / (float)rect4.Height);
                    //br.ScaleTransform(0.25f, 0.25f);
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.FillEllipse(br, rectImg);
                    g.DrawEllipse(new Pen(Color.White, 3), rectImg);
                }
                return(bmap);
            }
        }
Example #6
0
        public void ScaleTransform()
        {
            TextureBrush t = new TextureBrush(image);

            t.ScaleTransform(2, 4);
            float[] elements = t.Transform.Elements;
            Assert.AreEqual(2, elements[0], 0.1, "matrix.0");
            Assert.AreEqual(0, elements[1], 0.1, "matrix.1");
            Assert.AreEqual(0, elements[2], 0.1, "matrix.2");
            Assert.AreEqual(4, elements[3], 0.1, "matrix.3");
            Assert.AreEqual(0, elements[4], 0.1, "matrix.4");
            Assert.AreEqual(0, elements[5], 0.1, "matrix.5");

            t.ScaleTransform(0.5f, 0.25f);
            Assert.IsTrue(t.Transform.IsIdentity, "Transform.IsIdentity");
        }
Example #7
0
        private void SetupChart(ZedGraphControl zgc)
        {
            var pane = zgc.GraphPane;

            pane.Border.IsVisible          = false;
            pane.Title.IsVisible           = false;
            pane.XAxis.Title.Text          = "Volumenstrom Q in m³/h";
            pane.XAxis.Type                = AxisType.Exponent;
            pane.XAxis.Scale.Exponent      = 0.7;
            pane.XAxis.Scale.MajorStep     = 1;
            pane.XAxis.Scale.Min           = 0;
            pane.XAxis.MajorGrid.IsVisible = true;
            //pane.XAxis.MajorGrid.DashOff = 0;
            pane.YAxis.Title.Text = "Meter Wassersäule H in mWS";

            pane.Legend.Border.IsVisible = false;


            var texBrush = new TextureBrush(m_BackgroundLogo, System.Drawing.Drawing2D.WrapMode.Clamp);

            texBrush.TranslateTransform(-247.5F, -246.15F);
            texBrush.ScaleTransform(0.45F, 0.45F);

            var bgFill = new Fill(texBrush, false)
            {
                AlignH = AlignH.Center,
                AlignV = AlignV.Center
            };

            pane.Chart.Fill = bgFill;
        }
Example #8
0
        /// <summary>
        /// 椭圆形缩放
        /// </summary>
        /// <param name="bArr">图片字节流</param>
        /// <param name="width">目标宽度,若为0,表示宽度按比例缩放</param>
        /// <param name="height">目标长度,若为0,表示长度按比例缩放</param>
        public static byte[] GetEllipseThumbnail(byte[] bArr, int width, int height)
        {
            if (bArr == null)
            {
                return(null);
            }
            MemoryStream ms  = new MemoryStream(bArr);
            Bitmap       bmp = (Bitmap)Image.FromStream(ms);

            Bitmap newBmp = new Bitmap(width, height);

            using (Graphics g = Graphics.FromImage(newBmp))
            {
                using (TextureBrush br = new TextureBrush(bmp))
                {
                    br.ScaleTransform(width / (float)bmp.Width, height / (float)bmp.Height);
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.FillEllipse(br, new Rectangle(Point.Empty, new Size(width, height)));
                }
            }
            MemoryStream newMs = new MemoryStream();

            newBmp.Save(newMs, System.Drawing.Imaging.ImageFormat.Png);
            byte[] result = newMs.ToArray();

            bmp.Dispose();
            newBmp.Dispose();
            ms.Close();
            newMs.Dispose();

            return(result);
        }
Example #9
0
 public void ScaleTransform_InvalidOrder_ThrowsArgumentException(MatrixOrder matrixOrder)
 {
     using (var image = new Bitmap(10, 10))
         using (var brush = new TextureBrush(image))
         {
             AssertExtensions.Throws <ArgumentException>(null, () => brush.ScaleTransform(1, 2, matrixOrder));
         }
 }
Example #10
0
 public void ScaleTransform_InvalidOrder()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         TextureBrush t = new TextureBrush(image);
         t.ScaleTransform(1, 1, (MatrixOrder)Int32.MinValue);
     });
 }
Example #11
0
        /// <summary>
        /// 创建填充背景使用的画刷对象
        /// </summary>
        /// <param name="left">要绘制背景区域的左端坐标</param>
        /// <param name="top">要绘制背景区域的顶端坐标</param>
        /// <param name="width">要绘制背景区域的宽度</param>
        /// <param name="height">要绘制背景区域的高度</param>
        /// <param name="unit">绘制图形使用的单位</param>
        /// <returns>创建的画刷对象</returns>
        /// <remarks>
        /// 若设置了背景图片则创建图片样式的画刷对象,若设置了图案则创建带图案的画刷对象,
        /// 若设置了渐变设置则创建带渐变的画刷对象,否则创建纯色画刷对象。
        /// </remarks>
        public Brush CreateBrush(
            float left,
            float top,
            float width,
            float height,
            System.Drawing.GraphicsUnit unit)
        {
            if (intStyle == XBrushStyleConst.Disabled)
            {
                return(null);
            }

            if (myImage != null && myImage.Value != null)
            {
                System.Drawing.TextureBrush brush = new TextureBrush(myImage.Value);
                if (bolRepeat)
                {
                    brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
                }
                else
                {
                    brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp;
                }
                float rate = (float)GraphicsUnitConvert.GetRate(
                    unit,
                    System.Drawing.GraphicsUnit.Pixel);
                //brush.Transform.Translate(fOffsetX, fOffsetY);
                brush.TranslateTransform(fOffsetX, fOffsetY);
                brush.ScaleTransform(rate, rate);
                return(brush);
            }
            if (intStyle == XBrushStyleConst.Solid)
            {
                return(new SolidBrush(intColor));
            }
            else
            {
                if (( int )intStyle < 1000)
                {
                    System.Drawing.Drawing2D.HatchStyle style = (System.Drawing.Drawing2D.HatchStyle)intStyle;
                    return(new System.Drawing.Drawing2D.HatchBrush(
                               (System.Drawing.Drawing2D.HatchStyle)intStyle,
                               intColor,
                               intColor2));
                }
                else
                {
                    return(new System.Drawing.Drawing2D.LinearGradientBrush(
                               new RectangleF(left, top, width, height),
                               intColor,
                               intColor2,
                               (System.Drawing.Drawing2D.LinearGradientMode)(intStyle - 1000)));
                }
            }
            //return new SolidBrush(intColor);
        }
Example #12
0
        public override Brush GetBrush(Figure figure)
        {
            if (Image == null)
            {
                return(new SolidBrush(Color.Transparent));
            }
            var textureBrush = new TextureBrush(Image, WrapMode);

            textureBrush.ScaleTransform(Scale, Scale);
            return(textureBrush);
        }
Example #13
0
        // </snippet7>

        // Snippet for: M:System.Drawing.TextureBrush.ScaleTransform(System.Single,System.Single,System.Drawing.Drawing2D.MatrixOrder)
        // <snippet8>
        public void ScaleTransform_Example2(PaintEventArgs e)
        {
            // Create a TextureBrush object.
            TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg"));

            // Scale the texture image 2X in the x-direction.
            tBrush.ScaleTransform(2, 1, MatrixOrder.Prepend);

            // Fill a rectangle with tBrush.
            e.Graphics.FillRectangle(tBrush, 0, 0, 100, 100);
        }
Example #14
0
        /// <inheritdoc/>
        public override Brush CreateBrush(RectangleF rect, float scaleX, float scaleY)
        {
            if (image == null)
            {
                ForceLoadImage();
            }
            TextureBrush brush = new TextureBrush(image, WrapMode);

            brush.TranslateTransform(rect.Left + ImageOffsetX * scaleX, rect.Top + ImageOffsetY * scaleY);
            brush.ScaleTransform(scaleX, scaleY);
            return(brush);
        }
Example #15
0
        /// <summary>
        /// 将图片框改成圆角的方法
        /// </summary>
        /// <param name="img"></param>
        /// <param name="rec"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        private Image CutEllipse(Image img, Rectangle rec, Size size)
        {
            Bitmap bitmap = new Bitmap(size.Width, size.Height);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                TextureBrush br = new TextureBrush(img, System.Drawing.Drawing2D.WrapMode.Clamp, rec);
                br.ScaleTransform(bitmap.Width / (float)rec.Width, bitmap.Height / (float)rec.Height);
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                g.FillEllipse(br, new Rectangle(Point.Empty, size));
            }
            return(bitmap);
        }
Example #16
0
        private void SetNewTileSizes(PaintEventArgs e)
        {
            bounds     = e.Graphics.VisibleClipBounds;
            tileWidth  = bounds.Width / maze.width;
            tileHeight = bounds.Height / maze.height;
            playerSize = new SizeF(tileWidth * playerSizeMultiplicator,
                                   tileHeight * playerSizeMultiplicator);
            wallbrush.ResetTransform();
            wallbrush.ScaleTransform(tileWidth / wallScaleFactor, tileHeight / wallScaleFactor);

            grassbrush.ResetTransform();
            grassbrush.ScaleTransform(tileWidth / grassScaleFactor, tileHeight / grassScaleFactor);
        }
Example #17
0
        public void ScaleTransform_MaxMin()
        {
            TextureBrush t = new TextureBrush(image);

            t.ScaleTransform(Single.MaxValue, Single.MinValue);
            float[] elements = t.Transform.Elements;
            Assert.AreEqual(Single.MaxValue, elements[0], 1e33, "matrix.0");
            Assert.AreEqual(0, elements[1], 0.1, "matrix.1");
            Assert.AreEqual(0, elements[2], 0.1, "matrix.2");
            Assert.AreEqual(Single.MinValue, elements[3], 1e33, "matrix.3");
            Assert.AreEqual(0, elements[4], 0.1, "matrix.4");
            Assert.AreEqual(0, elements[5], 0.1, "matrix.5");
        }
Example #18
0
        /// <summary>
        /// Creates a brush from an image.
        /// </summary>
        /// <param name="boundingBox">The bounding box to fit the brush in.</param>
        /// <param name="fileName">The filename to load the image from. This filename should be relative to the images
        /// folder of the current style.</param>
        /// <returns>The brush created from the image.</returns>
        private Brush BrushFromImage(Rectangle boundingBox, string fileName)
        {
            var img   = ImageCache.Get(fileName);
            var gu    = GraphicsUnit.Pixel;
            var imgBb = img.GetBounds(ref gu);

            // Create a texture brush from the image.
            var tex = new TextureBrush(img, imgBb);

            tex.TranslateTransform(boundingBox.Left, boundingBox.Top);
            tex.ScaleTransform(boundingBox.Width / imgBb.Width, boundingBox.Height / imgBb.Height);

            return(tex);
        }
Example #19
0
        private void PaintFigure(string @path, char pozition_X, char pozition_Y)
        {
            Graphics graphics   = panel.CreateGraphics();
            Point    startPoint = new Point((int)(panel.Width * 0.05) + 3, (int)(panel.Height * 0.05) + 3);
            Size     size       = new Size((int)(panel.Width * 0.9f / 8), (int)(panel.Height * 0.9f / 8));

            startPoint.X += size.Width * ((int)pozition_X - 65);
            startPoint.Y += size.Width * (8 - Convert.ToInt32(pozition_Y) + 48);
            Rectangle    rectangle = new Rectangle(startPoint, size);
            TextureBrush texture   = new TextureBrush(new Bitmap(path));

            texture.TranslateTransform(startPoint.X, startPoint.Y);
            texture.ScaleTransform((float)size.Width / texture.Image.Width, (float)size.Height / texture.Image.Height);
            graphics.FillRectangle(texture, rectangle);
        }
Example #20
0
        /// <summary>Draws a hatch component on the specified path.</summary>
        /// <param name="graphics">The specified graphics to draw on.</param>
        /// <param name="hatch">The hatch type.</param>
        /// <param name="hatchGraphicsPath">The hatch path to fill.</param>
        public static void DrawHatch(Graphics graphics, Hatch hatch, GraphicsPath hatchGraphicsPath)
        {
            if (!hatch.Visible)
            {
                return;
            }

            HatchBrush _hatchBrush = new HatchBrush(hatch.Style, hatch.ForeColor, hatch.BackColor);

            using (TextureBrush _textureBrush = GraphicsManager.DrawTextureUsingHatch(_hatchBrush))
            {
                _textureBrush.ScaleTransform(hatch.Size.Width, hatch.Size.Height);
                graphics.FillPath(_textureBrush, hatchGraphicsPath);
            }
        }
        /// <summary>Draws a hatch component on the specified path.</summary>
        /// <param name="graphics">The specified graphics to draw on.</param>
        /// <param name="hatch">The hatch type.</param>
        /// <param name="hatchPath">The hatch path to fill.</param>
        public static void RenderHatch(Graphics graphics, Hatch hatch, GraphicsPath hatchPath)
        {
            if (!hatch.Visible)
            {
                return;
            }

            HatchBrush hatchBrush = new HatchBrush(hatch.Style, hatch.ForeColor, hatch.BackColor);

            using (TextureBrush textureBrush = BrushManager.HatchTextureBrush(hatchBrush))
            {
                textureBrush.ScaleTransform(hatch.Size.Width, hatch.Size.Height);
                graphics.FillPath(textureBrush, hatchPath);
            }
        }
Example #22
0
        /// <summary>
        /// 矩形 园型边框
        /// </summary>
        /// <param name="img"></param>
        /// <param name="rec"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static Image FillRoundRectangle(Image img, Rectangle rec, Size size)
        {
            Bitmap bitmap = new Bitmap(size.Width, size.Height);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                using (TextureBrush br = new TextureBrush(img, System.Drawing.Drawing2D.WrapMode.Clamp))
                {
                    //br.ScaleTransform(bitmap.Width / (float)rec.Width, bitmap.Height / (float)rec.Height);
                    br.ScaleTransform(bitmap.Width / (float)img.Width, bitmap.Height / (float)img.Height);
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.FillPath(br, GetRoundRectangle(rec, 5));
                }
            }
            return(bitmap);
        }
Example #23
0
        public Image CutEllipse(Image img, Rectangle rec, Size size, string imgSavePath)
        {
            Bitmap bitmap = new Bitmap(size.Width, size.Height);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                using (TextureBrush br = new TextureBrush(img, System.Drawing.Drawing2D.WrapMode.Clamp, rec))
                {
                    br.ScaleTransform(bitmap.Width / (float)rec.Width, bitmap.Height / (float)rec.Height);
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.FillEllipse(br, new Rectangle(Point.Empty, size));
                }
            }
            bitmap.Save(imgSavePath, System.Drawing.Imaging.ImageFormat.Png);
            return(null);
        }
Example #24
0
        /// <summary>
        /// 改变图片形状
        /// </summary>
        /// <param name="img"></param>
        /// <param name="rec">要求小于或等于size</param>
        /// <param name="size">要求大于或等于rec</param>
        /// <returns></returns>
        public static Image ChangeShape(Image img, Rectangle rec, Size size)
        {
            Bitmap bitmap = new Bitmap(size.Width, size.Height);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                using (TextureBrush br = new TextureBrush(img, WrapMode.Clamp, rec))
                {
                    br.ScaleTransform(bitmap.Width / (float)rec.Width, bitmap.Height / (float)rec.Height);
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.FillEllipse(br, new Rectangle(Point.Empty, size));
                }
            }

            return(bitmap);
        }
Example #25
0
        /// <summary>
        /// 直角图变转圆图
        /// </summary>
        /// <param name="img"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static Bitmap CutEllipse(Image img, int width, int height)
        {
            Bitmap bitmap = new Bitmap(width, height);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                using (TextureBrush br = new TextureBrush(img, System.Drawing.Drawing2D.WrapMode.Clamp, new Rectangle(0, 0, width, height)))
                {
                    br.ScaleTransform(bitmap.Width / (float)width, bitmap.Height / (float)height);
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.FillEllipse(br, new Rectangle(Point.Empty, new Size(width, height)));
                }
            }
            return(bitmap);
        }
Example #26
0
        public static bool MarkImage(WatermarkArgs watermarkArgs)
        {
            try
            {
                var baseImageName   = watermarkArgs.InputBaseImage;
                var waterImageName  = watermarkArgs.InputWaterImage;
                var outputImageName = watermarkArgs.OutputImage;
                var waterScale      = watermarkArgs.WaterScale;

                if (File.Exists(outputImageName) && watermarkArgs.ForceWrite == false)
                {
                    _Log.WriteWarning($"File already exists! Cancelling operation for {outputImageName}");
                    return(false);
                }

                using (var baseImage = Image.FromFile(baseImageName))
                    using (var waterImage = Image.FromFile(waterImageName))
                        using (var baseGraphics = Graphics.FromImage(baseImage))
                            using (var waterBrush = new TextureBrush(waterImage, System.Drawing.Drawing2D.WrapMode.Tile))
                            {
                                waterBrush.RotateTransform(-45);
                                waterBrush.ScaleTransform((float)waterScale, (float)waterScale);

                                baseGraphics.FillRectangle(waterBrush,
                                                           new Rectangle(
                                                               new Point(0, 0),
                                                               new Size(baseImage.Width, baseImage.Height)
                                                               ));

                                baseImage.Save(outputImageName, ImageFormat.Png);
                            }

                watermarkArgs.ParentTask?.IncrementProgress();

                return(true);
            }
            catch (Exception exception)
            {
                _Log.WriteException(exception);
            }

            return(false);
        }
Example #27
0
        public MazeGame(Form mainForm, Maze maze)
        {
            this.mainForm = mainForm;
            this.maze     = maze;
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
            updateMaze = true;
            Console.WriteLine("Set update Maze bool to true!");
            Width  = 600;
            Height = 600;
            Text   = "MazeRunner! - have fun. PRESS SPACE TO AUTO WALK!";
            Console.WriteLine("Loading brushes!");
            grassbrush = new TextureBrush(new Bitmap(pathOfExecutable + "Resources/Images/grassTexture.png"));
            grassbrush.ScaleTransform(tileWidth / grassScaleFactor, tileHeight / grassScaleFactor);

            wallbrush = new TextureBrush(new Bitmap(pathOfExecutable + "Resources/Images/stoneTexture.png"));
            wallbrush.ScaleTransform(tileWidth / wallScaleFactor, tileHeight / wallScaleFactor);
            SetTimer();
            runner = new MazeRunner(this);
        }
Example #28
0
        /// <summary>
        /// 将正方形图片切为圆形
        /// </summary>
        /// <param name="img"></param>
        /// <param name="rec"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static Image CutEllipse(Image img, Rectangle rec, Size size)
        {
            try
            {
                Bitmap bitmap = new Bitmap(size.Width, size.Height);
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    using (TextureBrush br = new TextureBrush(img, System.Drawing.Drawing2D.WrapMode.Clamp, rec))
                    {
                        br.ScaleTransform(bitmap.Width / (float)rec.Width, bitmap.Height / (float)rec.Height);
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        g.FillEllipse(br, new Rectangle(Point.Empty, size));
                    }
                }
                return(bitmap);
            }
            catch (Exception ex) {}

            return(null);
        }
Example #29
0
        protected override Pen getPen(Graphics gp)
        {
            var scale = gp.Transform.Elements[0];

            if (mouseDown)
            {
                var grid = new Bitmap(20, 20);
                var g    = Graphics.FromImage(grid);
                g.FillRectangle(Brushes.LightGray, 0, 0, 10, 10);
                g.FillRectangle(Brushes.LightGray, 10, 10, 10, 10);
                g.FillRectangle(Brushes.White, 0, 10, 10, 10);
                g.FillRectangle(Brushes.White, 10, 00, 10, 10);
                var brush = new TextureBrush(grid);
                brush.ScaleTransform(1 / scale, 1 / scale);
                return(new Pen(brush, Width));
            }
            else
            {
                return(new Pen(Color.Transparent, Width));
            }
        }
Example #30
0
        public override void Render(FrameEventArgs e)
        {
            float width = sceneManager.Width, height = sceneManager.Height, fontSize = Math.Min(width, height) / 30f;

            InputManager inputManager = InputManager.Instance();
            string       currentInput = "Current Input Device is set to: " + inputManager.GetControllerType();

            GUI.Label(new Rectangle(0, (int)(height - (2 * fontSize)), (int)width, (int)(fontSize * 2f)), currentInput, (int)fontSize, StringAlignment.Center);

            texture.ResetTransform();
            texture.TranslateTransform((int)(width * 7f / 12f), (int)(height / 4f));
            texture.ScaleTransform((width * 5f / 12f) / bitmap.Width, (height / 1.5f) / bitmap.Height);
            GUI.Texture(new Rectangle((int)(width * 7f / 12f), (int)(height / 4f), (int)(width * 5f / 12f), (int)(height / 1.5f)), texture);
            if (showError > 0)
            {
                GUI.Label(new Rectangle(0, (int)(height - (4 * fontSize)), (int)width, (int)(fontSize)), "Connect a GamePad first before selecting controller setup", (int)(fontSize / 1.5f), StringAlignment.Center);
            }
            else
            {
                showError = 0f;
            }

            base.Render(e);
        }