Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        protected virtual void PaintCore(Graphics g, Rectangle paintRect)
        {
            switch (this.paintMode)
            {
            case ImagePaintMode.None:
                g.DrawImageUnscaledAndClipped(this.cachedImage, new Rectangle(paintRect.Location, this.cachedImage.Size));
                break;

            case ImagePaintMode.Center:
                g.DrawImageUnscaledAndClipped(this.cachedImage, this.CenterRect(this.cachedImage.Size, paintRect));
                break;

            case ImagePaintMode.Tile:
            case ImagePaintMode.TileFlipX:
            case ImagePaintMode.TileFlipXY:
            case ImagePaintMode.TileFlipY:
                TextureBrush brush = new TextureBrush(this.cachedImage, this.GetWrapMode());
                brush.TranslateTransform(paintRect.X, paintRect.Y, MatrixOrder.Prepend);
                g.FillRectangle(brush, paintRect);
                brush.Dispose();
                break;

            case ImagePaintMode.CenterXStretchY:
                this.PaintSegmented(g, this.CenterRectX(this.cachedImage.Size, paintRect));
                break;

            case ImagePaintMode.CenterYStretchX:
                this.PaintSegmented(g, this.CenterRectY(this.cachedImage.Size, paintRect));
                break;

            case ImagePaintMode.CenterXTileY:
                this.PaintCenterXTileY(g, paintRect);
                break;

            case ImagePaintMode.CenterYTileX:
                this.PaintCenterYTileX(g, paintRect);
                break;

            case ImagePaintMode.Stretch:
                this.PaintSegmented(g, paintRect);
                break;

            case ImagePaintMode.StretchXTileY:
                this.PaintStretchXTileY(g, paintRect);
                break;

            case ImagePaintMode.StretchYTileX:
                this.PaintStretchYTileX(g, paintRect);
                break;

            case ImagePaintMode.StretchXYTileInner:
                this.PaintStretchXYTileInner(g, paintRect);
                break;
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public override Brush CreateBrush(RectangleF rect)
        {
            if (image == null)
            {
                ForceLoadImage();
            }
            TextureBrush brush = new TextureBrush(image, WrapMode);

            brush.TranslateTransform(rect.Left + ImageOffsetX, rect.Top + ImageOffsetY);
            return(brush);
        }
Exemplo n.º 4
0
 //Zmiana tła panelu GUI
 private void FormGraph_ShowPanelBackground()
 {
     gbPanel.BackColor       = System.Drawing.Color.LightGray;
     gbPanel.BackgroundImage = new Bitmap(gbPanel.Width, gbPanel.Height);
     using (TextureBrush brush = new TextureBrush(Properties.Resources.cell, WrapMode.Tile))
         using (Graphics g = Graphics.FromImage(gbPanel.BackgroundImage))
         {
             brush.TranslateTransform(PanelGUI.WebBoundary.X, PanelGUI.WebBoundary.Y);
             g.FillRectangle(brush, PanelGUI.WebBoundary);
         }
 }
Exemplo n.º 5
0
        // </snippet9>

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

            // Move the texture image 2X in the x-direction.
            tBrush.TranslateTransform(50, 0);

            // Fill a rectangle with tBrush.
            e.Graphics.FillRectangle(tBrush, 0, 0, 100, 100);
        }
Exemplo n.º 6
0
        private Image AddWaterMark(Image image, SageWorkOrder workOrder, long number)
        {
            var    watermarkImage = Image.FromStream(_storageProvider.GetFile(Path.Combine(_urlToFolderPhotoWorkOrders, "watermark.png")).OpenRead());
            var    newWidth       = image.Width / 7;
            var    newHeight      = newWidth * watermarkImage.Height / watermarkImage.Width;
            var    margin         = newWidth / 10;
            float  opacity        = (float)0.5;
            int    fontSize       = Convert.ToInt32(newHeight / 7);
            Stream fontStream     = _storageProvider.GetFile(Path.Combine(_urlToFolderFonts, "OpenSans-Bold.ttf")).OpenRead();
            PrivateFontCollection fonts;
            FontFamily            family = LoadFontFamily(fontStream, out fonts);
            Font theFont = new Font(family, fontSize);

            watermarkImage = ResizeImage(watermarkImage, new Size(newWidth, newHeight));
            // watermarkImage = ChangeOpacity(watermarkImage, opacity);

            using (var graphicsHandle = Graphics.FromImage(image))
                using (TextureBrush watermarkBrush = new TextureBrush(watermarkImage))
                {
                    graphicsHandle.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    int x = (margin);
                    int y = (image.Height - newHeight);
                    watermarkBrush.TranslateTransform(x, y);
                    graphicsHandle.FillRectangle(watermarkBrush, new Rectangle(new Point(x, y), new Size(newWidth, newHeight)));

                    using (var arialFont = theFont)
                    {
                        x = (image.Width - newWidth - margin);
                        y = (image.Height - newHeight - 4);
                        RectangleF   rectF1       = new RectangleF(x, y, newWidth, newHeight);
                        SolidBrush   brush        = new SolidBrush(Color.FromArgb(255, Color.White));
                        StringFormat stringFormat = new StringFormat()
                        {
                            Alignment     = StringAlignment.Center,
                            LineAlignment = StringAlignment.Center
                        };

                        graphicsHandle.FillRectangle(brush, Rectangle.Round(rectF1));
                        var pen = new Pen(Color.Black, 0.1f);
                        graphicsHandle.DrawRectangle(pen, Rectangle.Round(rectF1));
                        pen.Color = Color.Red;
                        RectangleF rectInside = new RectangleF(x + 2, y + 2, newWidth - 4, newHeight - 4);
                        graphicsHandle.DrawRectangle(pen, Rectangle.Round(rectInside));
                        var woDate = "";
                        if (workOrder.DateEntered != null)
                        {
                            woDate = workOrder.DateEntered.Value.Date.ToShortDateString();
                        }
                        graphicsHandle.DrawString($"WORK ORDER #{workOrder.WorkOrder}\r\n{woDate}\r\nIMAGE #{number}", arialFont, Brushes.Black, x + newWidth / 2, y + newHeight / 2, stringFormat);
                    }
                }
            return(image);
        }
Exemplo n.º 7
0
 public void ApplyWatermark(string sourceImagePath, string outputImagePath)
 {
     using (Image image = Image.FromFile(sourceImagePath))
         using (Graphics imageGraphics = Graphics.FromImage(image))
         {
             int x = (image.Width / 2 - _watermarkImage.Width / 2);
             int y = (image.Height / 2 - _watermarkImage.Height / 2);
             _watermarkBrush.TranslateTransform(x, y);
             imageGraphics.FillRectangle(_watermarkBrush, new Rectangle(new Point(x, y), new Size(_watermarkImage.Width + 1, _watermarkImage.Height)));
             image.Save(outputImagePath);
         }
 }
Exemplo n.º 8
0
        private void DrawMagnifier(Graphics g)
        {
            Point     mousePos = InputManager.MousePosition0Based;
            Rectangle currentScreenRect0Based = CaptureHelpers.ScreenToClient(Screen.FromPoint(InputManager.MousePosition).Bounds);
            int       offsetX = 10, offsetY = 10, infoTextOffset = 0, infoTextPadding = 3;
            Rectangle infoTextRect = Rectangle.Empty;
            string    infoText = string.Empty;

            if (Config.ShowInfo)
            {
                infoTextOffset = 10;

                CurrentPosition = InputManager.MousePosition;

                infoText = GetInfoText();
                Size textSize = g.MeasureString(infoText, infoFont).ToSize();
                infoTextRect.Size = new Size(textSize.Width + infoTextPadding * 2, textSize.Height + infoTextPadding * 2);
            }

            using (Bitmap magnifier = Magnifier(SurfaceImage, mousePos, Config.MagnifierPixelCount, Config.MagnifierPixelCount, Config.MagnifierPixelSize))
            {
                int x = mousePos.X + offsetX;

                if (x + magnifier.Width > currentScreenRect0Based.Right)
                {
                    x = mousePos.X - offsetX - magnifier.Width;
                }

                int y = mousePos.Y + offsetY;

                if (y + magnifier.Height + infoTextOffset + infoTextRect.Height > currentScreenRect0Based.Bottom)
                {
                    y = mousePos.Y - offsetY - magnifier.Height - infoTextOffset - infoTextRect.Height;
                }

                if (Config.ShowInfo)
                {
                    infoTextRect.Location = new Point(x + (magnifier.Width / 2) - (infoTextRect.Width / 2), y + magnifier.Height + infoTextOffset);
                    DrawInfoText(g, infoText, infoTextRect, 3);
                }

                g.SetHighQuality();

                using (TextureBrush brush = new TextureBrush(magnifier))
                {
                    brush.TranslateTransform(x, y);
                    g.FillEllipse(brush, x, y, magnifier.Width, magnifier.Height);
                    g.DrawEllipse(Pens.White, x - 1, y - 1, magnifier.Width + 2, magnifier.Height + 2);
                    g.DrawEllipse(Pens.Black, x, y, magnifier.Width, magnifier.Height);
                }
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.Clear(BackColor);

            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            //Draw Background
            //Draw Vertical Line
            e.Graphics.FillRectangle(MaterialSkinManager.Instance.ColorScheme.PrimaryBrush, new Rectangle(AvatarRect.X + (int)(AvatarRect.Width / 2) - 5, -5, 10, Height + 5));
            //Draw Avatar
            if (_User == null)
            {
                e.Graphics.FillEllipse(SkinManager.ColorScheme.PrimaryBrush, AvatarRect);
            }
            else
            {
                using (TextureBrush brush = new TextureBrush(_UserScaled))
                {
                    brush.WrapMode = WrapMode.Clamp;
                    Point xDislpayCenterRelativ = new Point(AvatarRect.Width / 2, AvatarRect.Height / 2);
                    Point xImageCenterRelativ   = new Point(_UserScaled.Width / 2, _UserScaled.Height / 2);
                    Point xOffSetRelativ        = new Point(xDislpayCenterRelativ.X - xImageCenterRelativ.X, xDislpayCenterRelativ.Y - xImageCenterRelativ.Y);

                    Point xAbsolutePixel = xOffSetRelativ + new Size(AvatarRect.Location);
                    brush.TranslateTransform(xAbsolutePixel.X, xAbsolutePixel.Y);
                    e.Graphics.FillEllipse(brush, AvatarRect);
                }
            }
            // Draw Card
            DrawHelper.drawShadow(e.Graphics, CardShadow, 4, Color.Black);
            e.Graphics.FillPath(SkinManager.getCardsBrush(), CardShadow);

            //Draw Strings
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            //Draw Time
            e.Graphics.DrawString(_Time.ToString("dd.MM.yyyy") + "\r\n" + _Time.ToString("HH:mm:ss"), SkinManager.FONT_TEXT, SkinManager.ColorScheme.TextBrush, TimeRectangle, _StringFormat);
            //Draw Avatar
            if (_User == null)
            {
                e.Graphics.DrawString(_UserInitialien, _UserInitialienFont, SkinManager.ColorScheme.TextBrush, AvatarRect, _StringFormat);
            }
            //Draw Title
            e.Graphics.DrawString(_Title, SkinManager.FONT_TITLE, SkinManager.ColorScheme.PrimaryBrush, TitleRect, _StringFormat);
            //Draw Content
            e.Graphics.DrawString(_Text, SkinManager.FONT_TEXT, SkinManager.ColorScheme.TextBrush, ContentRect, new StringFormat {
                LineAlignment = StringAlignment.Center
            });
            //Draw Name
            e.Graphics.DrawString(_UserName, SkinManager.FONT_TEXT, SkinManager.ColorScheme.TextBrush, NameRect, _StringFormat);

            e.Graphics.DrawString(_AdditionalInfo, SkinManager.FONT_TEXT, SkinManager.ColorScheme.TextBrush, AdditionalInfoRectangle, _StringFormat);
        }
Exemplo n.º 10
0
 private void ProcessImage(string name)
 {
     using (Image image = Image.FromFile(name))
         using (Image watermarkImage = Image.FromFile(Server.MapPath(WatermarkImageUrl)))
             using (Graphics imageGraphics = Graphics.FromImage(image))
                 using (TextureBrush watermarkBrush = new TextureBrush(watermarkImage)) {
                     int x = (image.Width - watermarkImage.Width);
                     int y = (image.Height - watermarkImage.Height);
                     watermarkBrush.TranslateTransform(x, y);
                     imageGraphics.FillRectangle(watermarkBrush, new Rectangle(new Point(x, y), new Size(watermarkImage.Width + 1, watermarkImage.Height)));
                     image.Save(Server.MapPath(ProcessedImageFolder + "\\" + Path.GetFileName(name)));
                 }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Draw the background image at the required location repeating it over the Y axis.<br/>
        /// Adjust location to top if starting location doesn't include all the range (adjusted to center or bottom).
        /// </summary>
        private static void DrawRepeatY(IGraphics g, ImageLoadHandler imageLoadHandler, RectangleF rectangle, Rectangle srcRect, Rectangle destRect, Size imgSize)
        {
            while (destRect.Y > rectangle.Y)
            {
                destRect.Y -= imgSize.Height;
            }

            using (var brush = new TextureBrush(imageLoadHandler.Image, srcRect))
            {
                brush.TranslateTransform(destRect.X, destRect.Y);
                g.FillRectangle(brush, destRect.X, rectangle.Y, srcRect.Width, rectangle.Height);
            }
        }
Exemplo n.º 12
0
 protected override void OnPaint(PaintEventArgs e)
 {
     base.OnPaint(e);
     if (outputImage != null)
     {
         Graphics gfx     = e.Graphics;
         Point    topLeft = getTopLeftPosition(true);
         transTexture.ResetTransform();
         transTexture.TranslateTransform(topLeft.X, topLeft.Y);
         gfx.FillRectangle(transTexture, 0, 0, this.Width, this.Height);
         gfx.DrawImage(outputImage, getTopLeftPosition(false));
     }
 }
Exemplo n.º 13
0
        void DrawBorder(Graphics graphics, Bitmap image, Rectangle rectangle)
        {
            if (image == null)
            {
                return;
            }

            using (var brush = new TextureBrush(image))
            {
                brush.TranslateTransform(rectangle.Left, rectangle.Top);
                graphics.FillRectangle(brush, rectangle);
            }
        }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:DXBall.Ball"/> class.
 /// </summary>
 /// <param name="_posX">Position x.</param>
 /// <param name="_posY">Position y.</param>
 public Ball(float _posX, float _posY)
 {
     resPicture = Properties.Resources.ballnormal;
     ballBrush  = new TextureBrush(resPicture);
     ballBrush.TranslateTransform(_posX, _posY);
     ballRectangle   = new RectangleF(_posX, _posY, 16f, 16f);
     posX            = _posX;
     posY            = _posY;
     OtherRectangles = new List <RectangleF>();
     touchedLine     = false;
     FalledDown      = false;
     AtStartPosition = true;
 }
Exemplo n.º 15
0
        public void TranslateTransform()
        {
            TextureBrush t = new TextureBrush(image);

            t.TranslateTransform(1, 1);
            float[] elements = t.Transform.Elements;
            Assert.AreEqual(1, 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(1, elements[3], 0.1, "matrix.3");
            Assert.AreEqual(1, elements[4], 0.1, "matrix.4");
            Assert.AreEqual(1, elements[5], 0.1, "matrix.5");

            t.TranslateTransform(-1, -1);
            elements = t.Transform.Elements;
            Assert.AreEqual(1, elements[0], 0.1, "revert.matrix.0");
            Assert.AreEqual(0, elements[1], 0.1, "revert.matrix.1");
            Assert.AreEqual(0, elements[2], 0.1, "revert.matrix.2");
            Assert.AreEqual(1, elements[3], 0.1, "revert.matrix.3");
            Assert.AreEqual(0, elements[4], 0.1, "revert.matrix.4");
            Assert.AreEqual(0, elements[5], 0.1, "revert.matrix.5");
        }
Exemplo n.º 16
0
        public void PutCollectable()
        {
            collectableBrush.ResetTransform();
            collectableBrush.TranslateTransform(posX, posY);
            collRectangle.X = posX;
            collRectangle.Y = posY;

            if (posY > 715f)
            {
                fallen    = true;
                collected = false;
            }
        }
Exemplo n.º 17
0
 private static void AddTestWaterMark([NotNull] Image image)
 {
     using (var watermarkImage = Properties.Resources.test)
         using (var imageGraphics = Graphics.FromImage(image))
             using (var watermarkBrush = new TextureBrush(watermarkImage))
             {
                 var x = image.Width / 2 - watermarkImage.Width / 2;
                 var y = image.Height / 2 - watermarkImage.Height / 2;
                 watermarkBrush.TranslateTransform(x, y);
                 imageGraphics.FillRectangle(watermarkBrush,
                                             new Rectangle(new Point(x, y), new Size(watermarkImage.Width + 1, watermarkImage.Height)));
             }
 }
Exemplo n.º 18
0
        public TextureBrush PutAnimation()
        {
            TextureBrush ret = tiledTexture.GetBrush(currentTile);

            ret.ResetTransform();
            ret.TranslateTransform(posX, posY);
            animationRectangle.X = posX; animationRectangle.Y = posY;
            currentTile++; if (currentTile == tiledTexture.TilesLength)
            {
                currentTile = 0; OnAnimationTurned();
            }
            return(ret);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Moves the line.
        /// </summary>
        public void MoveLine()
        {
            if (Math.Abs(lineRectangle.Width - 64f) < 5f)
            {
                if (posX < 65f)
                {
                    posX = 65f;
                }
                else if (posX > 830f)
                {
                    posX = 830f;
                }
            }
            else if (Math.Abs(lineRectangle.Width - 128f) < 5f)
            {
                if (posX < 64f)
                {
                    posX = 64f;
                }
                else if (posX > 768f)
                {
                    posX = 768f;
                }
            }
            else if (Math.Abs(lineRectangle.Width - 256f) < 5f)
            {
                if (posX < 60f)
                {
                    posX = 60f;
                }
                else if (posX > 643f)
                {
                    posX = 643f;
                }
            }

            lineBrush.ResetTransform();
            lineBrush.TranslateTransform(posX, posY);
            lineRectangle.X = posX;
            lineRectangle.Y = posY;

            if (moveRight)
            {
                posX += 20;
            }

            if (moveLeft)
            {
                posX -= 20;
            }
        }
Exemplo n.º 20
0
        public static PackedSpriteMapMeta PackListOfImages(Frame[] imagesToPack, int frameWidth, int frameHeight, FrameDisposal frameDisposal)
        {
            var size        = Size.GetDimensions(frameWidth, frameHeight, imagesToPack.Length);
            var sprite      = new Bitmap(frameWidth * size.Cols, frameHeight * size.Rows);
            var spriteFrame = new Bitmap(frameWidth, frameHeight);

            using (var g = Graphics.FromImage(sprite))
            {
                using (var sg = Graphics.FromImage(spriteFrame))
                {
                    g.FillRectangle(new SolidBrush(Color.Transparent), 0, 0, sprite.Width, sprite.Height);
                    sg.FillRectangle(new SolidBrush(Color.Transparent), 0, 0, sprite.Width, sprite.Height);

                    int x = 0, y = 0;
                    for (int i = 0; i < imagesToPack.Count(); i++)
                    {
                        var bmp   = imagesToPack[i];
                        var brush = new TextureBrush(bmp.Image, System.Drawing.Drawing2D.WrapMode.Clamp);

                        brush.TranslateTransform(bmp.X, bmp.Y);

                        if (frameDisposal == FrameDisposal.Composite)
                        {
                            sg.FillRectangle(brush, 0, 0, bmp.Width + bmp.X, bmp.Height + bmp.Y);
                            brush.Dispose();
                            brush = new TextureBrush(spriteFrame, System.Drawing.Drawing2D.WrapMode.Clamp);
                        }


                        brush.TranslateTransform(x * frameWidth, y * frameHeight);
                        g.FillRectangle(brush, x * frameWidth, y * frameHeight, bmp.Width + bmp.X, bmp.Height + bmp.Y);

                        brush.Dispose();
                        if (++x >= size.Cols)
                        {
                            x = 0;
                            y++;
                        }
                    }
                }
            }
            return(new PackedSpriteMapMeta
            {
                Image = sprite,
                FrameHeight = frameHeight,
                FrameWidth = frameWidth,
                TotalFrames = imagesToPack.Length,
                Columns = size.Cols,
                Rows = size.Rows
            });
        }
        public BaWGUIProgressBar()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);

            BackColor      = Color.Transparent;
            DoubleBuffered = true;
            Font           = new Font("Arial", 16);
            MinimumSize    = new Size(60, 80);

            TB.TranslateTransform(0, -5, MatrixOrder.Prepend);

            P3 = new Pen(Color.FromArgb(190, 190, 190));
            B1 = new SolidBrush(Color.FromArgb(84, 83, 81));
        }
Exemplo n.º 22
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (iWaiting)
            {
                int x = (int)((ClientRectangle.Width - kImageWaiting.Width) * 0.5f);
                int y = (int)((ClientRectangle.Height - kImageWaiting.Height) * 0.5f);
                e.Graphics.DrawImage(kImageWaiting, x, y);

                iTextureBrush.ResetTransform();
                iTextureBrush.TranslateTransform(x, y);
                iTextureBrush.TranslateTransform(kImageWaiting.Width * 0.5f, kImageWaiting.Height * 0.5f);
                iTextureBrush.RotateTransform(iAngle);
                iTextureBrush.TranslateTransform(-kImageWaiting.Width * 0.5f, -kImageWaiting.Height * 0.5f);
                e.Graphics.FillRectangle(iTextureBrush, x, y, kImageWaiting.Width, kImageWaiting.Height);

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

                e.Graphics.DrawString(iMessage, Font, iBrushForeColour, new Rectangle(0, y + 75, ClientSize.Width, Font.Height), format);
            }
        }
Exemplo n.º 23
0
 public void MoveLine()
 {
     if (posX < 64f)
     {
         posX = 64f;
     }
     else if (posX > 768f)
     {
         posX = 768f;
     }
     lineBrush.ResetTransform();
     lineBrush.TranslateTransform(posX, posY);
     lineRectangle.X = posX; lineRectangle.Y = posY;
 }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
0
        /// <summary>
        /// 创建矩形笔刷
        /// </summary>
        /// <param name="x">起点X坐标</param>
        /// <param name="y">起点Y坐标</param>
        /// <param name="gridSizeNumW">宽</param>
        /// <param name="gridSizeNumH">高</param>
        /// <returns></returns>
        public static TextureBrush DrawRectangle(int x, int y, int gridSizeNumW, int gridSizeNumH, GridStyle gridStyle)
        {
            Bitmap   bit = new Bitmap(gridSizeNumW, gridSizeNumH);
            Graphics g   = Graphics.FromImage(bit);

            g.Clear(gridStyle.BgColor);
            g.DrawRectangle(new Pen(gridStyle.ShowGrid ? gridStyle.LineColor : gridStyle.BgColor, gridStyle.LineWidth), new Rectangle(-1, -1, gridSizeNumW, gridSizeNumH));
            g.Dispose();
            TextureBrush textureBrush = new TextureBrush(bit);

            textureBrush.TranslateTransform(x, y);

            return(textureBrush);
        }
Exemplo n.º 26
0
        public static void DrawShadow(Graphics g, Rectangle r)
        {
            r.Offset(shadowSize, shadowSize);
            TextureBrush shadowRightBrush = new TextureBrush(shadowRight, WrapMode.Tile);
            TextureBrush shadowDownBrush  = new TextureBrush(shadowDown, WrapMode.Tile);

            // Translate (move) the brushes so the top or left of the image matches the top or left of the
            // area where it's drawed. If you don't understand why this is necessary, comment it out.
            // Hint: The tiling would start at 0,0 of the control, so the shadows will be offset a little.
            //shadowDownBrush.TranslateTransform(0, r.Height - shadowSize);
            //shadowRightBrush.TranslateTransform(r.Width - shadowSize, 0);
            shadowDownBrush.TranslateTransform(0, r.Height + r.Y - shadowSize);
            shadowRightBrush.TranslateTransform(r.Width + r.X - shadowSize, 0);

            // Define the rectangles that will be filled with the brush.
            // (where the shadow is drawn)

            Rectangle shadowDownRectangle = new Rectangle(
                r.X + shadowSize + shadowMargin,                // X
                r.Y + r.Height - shadowSize,                    // Y
                r.Width - (2 * shadowSize + shadowMargin),      // width (stretches)
                shadowSize                                      // height
                );


            Rectangle shadowRightRectangle = new Rectangle(
                r.Width - shadowSize + r.X,                     // X
                shadowSize + shadowMargin + r.Y,                // Y
                shadowSize,                                     // width
                r.Height - (shadowSize * 2 + shadowMargin)      // height (stretches)
                );

            // And draw the shadow on the right and at the bottom.
            g.FillRectangle(shadowDownBrush, shadowDownRectangle);
            g.FillRectangle(shadowRightBrush, shadowRightRectangle);

            // Now for the corners, draw the 3 5x5 pixel images.
            g.DrawImage(shadowTopRight, new Rectangle(r.Width - shadowSize + r.X, shadowMargin + r.Y, shadowSize, shadowSize));
            g.DrawImage(shadowDownRight, new Rectangle(r.Width - shadowSize + r.X, r.Height - shadowSize + r.Y, shadowSize, shadowSize));
            g.DrawImage(shadowDownLeft, new Rectangle(shadowMargin + r.X, r.Height - shadowSize + r.Y, shadowSize, shadowSize));


            // Memory efficiency
            shadowDownBrush.Dispose();
            shadowRightBrush.Dispose();

            shadowDownBrush  = null;
            shadowRightBrush = null;
        }
Exemplo n.º 27
0
        private void PaintStretchXTileY(Graphics g, Rectangle paintRect)
        {
            Image    image = (Image) new Bitmap(paintRect.Width, this.cachedImage.Height, PixelFormat.Format32bppArgb);
            Graphics g1    = Graphics.FromImage(image);

            g1.InterpolationMode = this.interpolationMode;
            this.PaintSegmented(g1, new Rectangle(0, 0, paintRect.Width, this.cachedImage.Height));
            TextureBrush textureBrush = new TextureBrush(image, WrapMode.Tile);

            textureBrush.TranslateTransform((float)paintRect.X, (float)paintRect.Y, MatrixOrder.Prepend);
            g.FillRectangle((Brush)textureBrush, paintRect);
            g1.Dispose();
            image.Dispose();
            textureBrush.Dispose();
        }
Exemplo n.º 28
0
 private static void MergeImages(string path, string resultPath)
 {
     using (Image image = Image.FromFile(path))
         using (Image preaprewatermark = Image.FromFile(@"../../wzór.png"))
             using (Image watermarkImage = ScaleImage(preaprewatermark, image.Width, image.Height))
                 using (Graphics imageGraphics = Graphics.FromImage(image))
                     using (TextureBrush watermarkBrush = new TextureBrush(watermarkImage))
                     {
                         int x = (image.Width / 2 - watermarkImage.Width / 2);
                         int y = (image.Height / 2 - watermarkImage.Height / 2);
                         watermarkBrush.TranslateTransform(x, y);
                         imageGraphics.FillRectangle(watermarkBrush, new Rectangle(new Point(x, y), new Size(watermarkImage.Width + 1, watermarkImage.Height)));
                         image.Save(resultPath);
                     }
 }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
0
        public void Draw(Graphics g, RectangleF rf, GraphicsPath path)
        {
            if (_content == null)
            {
                return;
            }

            if (_data.IsImage)                                  //DrawImage
            {
                Image im = _data.GetBrushImage(_content);
                if (im == null)
                {
                    return;
                }

                if (_data.ImageMode == ImageDrawMode.Stretch)
                {
                    g.DrawImage(im, rf);
                }
                else if (_data.ImageMode == ImageDrawMode.Center)
                {
                    Region rgn = g.Clip;

                    Size  s = im.Size;
                    float x = rf.X + (rf.Width - s.Width) / 2;
                    float y = rf.Y + (rf.Height - s.Height) / 2;

                    g.SetClip(rf);
                    g.DrawImage(im, x, y);

                    //需要恢复,否则接下来的绘图不完整
                    g.SetClip(rgn, CombineMode.Replace);
                }
            }
            else                                                                //FillBrush
            {
                //如果是平铺图片模式,_brush需要偏移
                TextureBrush texture = _content as TextureBrush;
                if (texture != null)
                {
                    texture.ResetTransform();
                    texture.TranslateTransform(rf.X, rf.Y);
                }

                g.FillPath(_content, path);
            }
        }