Пример #1
0
        /// <summary>
        /// Pasa los frames necesarios de la aplicación
        /// </summary>
        public Bitmap PasarFrame()
        {
            NodoComponente  aux       = componentes.Cab;
            ImageAttributes atributos = new ImageAttributes();

            this.pintable.DrawImage(fondo, 0, 0);
            int i;

            i = 0;
            if (estaViva)
            {
                Color color = ((Bitmap)ListaImagenes[0]).GetPixel(0, 0);
                atributos.SetColorKey(color, color);
                while (aux != null)
                {
                    aux.Info.PasarFrame();
                    Rectangle destino = new Rectangle(puntoReferencia.X + aux.Info.DatoComponente.DistanciaPuntoReferencia.X, puntoReferencia.Y + aux.Info.DatoComponente.DistanciaPuntoReferencia.Y, aux.Info.DatoComponente.RectanguloFuente.Width, aux.Info.DatoComponente.RectanguloFuente.Height);
                    Bitmap    dibujo  = (Bitmap)ListaImagenes[i];
                    pintable.DrawImage(dibujo, destino, aux.Info.DatoComponente.RectanguloFuente.X, aux.Info.DatoComponente.RectanguloFuente.Y, aux.Info.DatoComponente.RectanguloFuente.Width, aux.Info.DatoComponente.RectanguloFuente.Height, GraphicsUnit.Pixel, atributos);
                    aux = aux.Siguiente;
                    i++;
                }
            }
            else
            {
                Color color = tumba.GetPixel(0, 0);
                atributos.SetColorKey(color, color);
                pintable.DrawImage(tumba, new Rectangle(puntoReferencia.X - tumba.Width / 2, puntoReferencia.Y - tumba.Height, tumba.Width, tumba.Height), 0, 0, tumba.Width, tumba.Height, GraphicsUnit.Pixel, atributos);
            }
            if (OnImagenCambiada != null)
            {
                OnImagenCambiada(this, bmp);
            }
            return(bmp);
        }
Пример #2
0
        public void drawMap(Graphics g, int width, int height, Point center)
        {
            try
            {
                int nScale = mapview.Getlevel(tlVectorControl1.ScaleRatio);
                if (nScale == -1)
                {
                    return;
                }
                LongLat longlat = LongLat.Empty;
                //计算中心点经纬度

                longlat = mapview.OffSet(mapview.ZeroLongLat, mapview.Getlevel(1), center.X, center.Y);
                ImageAttributes imageA = new ImageAttributes();
                longlat = mapview.OffSetZero(-(int)(center.X * tlVectorControl1.ScaleRatio), -(int)(center.Y * tlVectorControl1.ScaleRatio));

                int chose = Convert.ToInt32(ConfigurationSettings.AppSettings.Get("chose"));
                if (chose == 1)
                {
                    g.Clear(Color.White);//ColorTranslator.FromHtml("#EBEAE8")

                    Color color = ColorTranslator.FromHtml("#EBEAE8");
                    imageA.SetColorKey(color, color);
                }
                else if (chose == 2)
                {
                    Color color  = ColorTranslator.FromHtml("#F4F4FB");
                    Color color2 = ColorTranslator.FromHtml("#EFF0F1");//EFF0F1
                    //imageAttributes2.SetColorKey(color, color);
                    //imageAttributes2.SetColorKey(color2, color2);
                    imageA.SetColorKey(color2, color);
                }
                //imageA.
                //g.InterpolationMode = InterpolationMode.HighQualityBicubic;


                mapview.Paint(g, width, height, nScale, longlat.Longitude, longlat.Latitude, imageA);
                //绘制比例尺
                Point p1 = new Point(20, height - 30);
                Point p2 = new Point(20, height - 20);
                Point p3 = new Point(80, height - 20);
                Point p4 = new Point(80, height - 30);

                //g.DrawLines(new Pen(Color.Black, 2), new Point[4] { p1, p2, p3, p4 });
                //string str1 = string.Format("{0}公里", MapViewObj.GetMiles(nScale));
                //g.DrawString(str1, new Font("宋体", 10), Brushes.Black, 30, height - 40);
            }
            catch (Exception e1)
            {
            }
        }
Пример #3
0
        private void OnMapNewTileAvailable(TileInfo tileInfo, Bitmap bitmap)
        {
            if (_onlyRedrawWhenComplete)
            {
                return;
            }

            var mapNewTileAvailable = MapNewTileAvaliable;

            if (mapNewTileAvailable != null)
            {
                var bb = new Envelope(new Coordinate(tileInfo.Extent.MinX, tileInfo.Extent.MinY), new Coordinate(tileInfo.Extent.MaxX, tileInfo.Extent.MaxY));
                using (var ia = new ImageAttributes())
                {
                    if (!_transparentColor.IsEmpty)
                    {
                        ia.SetColorKey(_transparentColor, _transparentColor);
                    }
#if !PocketPC
                    ia.SetWrapMode(WrapMode.TileFlipXY);
#endif
                    int tileWidth  = _source.Schema.GetTileWidth(tileInfo.Index.Level);
                    int tileHeight = _source.Schema.GetTileHeight(tileInfo.Index.Level);
                    mapNewTileAvailable(this, bb, bitmap, tileWidth, tileHeight, ia);
                }
            }
        }
Пример #4
0
            private Image CreateImage(Image value, Color transparentColor)
            {
                int             imageWidth;
                int             imageHeight;
                Bitmap          bitmap;
                Graphics        graphics;
                ImageAttributes imageAttributes;

                if (transparentColor.A == 0)
                {
                    imageAttributes = null;
                }
                else
                {
                    imageAttributes = new ImageAttributes();
                    imageAttributes.SetColorKey(transparentColor, transparentColor);
                }

                bitmap   = new Bitmap(imageWidth = this.imageSize.Width, imageHeight = this.imageSize.Height, PixelFormat.Format32bppArgb);
                graphics = Graphics.FromImage(bitmap);
                graphics.DrawImage(value, new Rectangle(0, 0, imageWidth, imageHeight), 0, 0, value.Width, value.Height, GraphicsUnit.Pixel, imageAttributes);
                graphics.Dispose();

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

                ReduceColorDepth(bitmap);
                return(bitmap);
            }
Пример #5
0
        private void DrawImageManaged(Graphics g, Rectangle source, Rectangle destination, Color key)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }


            ImageAttributes attr = new ImageAttributes();

            if (key.IsEmpty)
            {
                if (image is Bitmap)
                {
                    key = ((Bitmap)image).GetPixel(0, 0);
                }
            }
            attr.SetColorKey(key, key);
            if (source.IsEmpty)
            {
                source = new Rectangle(0, 0, image.Width, image.Height);
            }

            g.DrawImage(image, destination, source.Left, source.Top, source.Width, source.Height, GraphicsUnit.Pixel, attr);
        }
Пример #6
0
        public void Save(string fileName, bool compositeBackground)
        {
            iApp.Factory.ActivateLoadTimer("Saving...");
            Device.Thread.Start(() =>
            {
                iApp.File.EnsureDirectoryExists(fileName);
                using (var temp = new Bitmap(_signatureBitmap.Width, _signatureBitmap.Height))
                    using (var g = Graphics.FromImage(temp))
                    {
                        g.Clear(System.Drawing.Color.Transparent);
                        if (compositeBackground)
                        {
                            PaintBackground(g);
                        }
                        var attr     = new ImageAttributes();
                        var transKey = System.Drawing.Color.Lime;
                        attr.SetColorKey(transKey, transKey);
                        var dstRect = new Rectangle(0, 0, temp.Width, temp.Height);
                        g.DrawImage(_signatureBitmap, dstRect, 0, 0, temp.Width, temp.Height, GraphicsUnit.Pixel, attr);
                        temp.Save(fileName, ImageFormat.Png);
                    }

                Device.Thread.ExecuteOnMainThread(() =>
                {
                    var save = DrawingSaved;
                    if (save != null)
                    {
                        save(this, new SaveEventArgs(fileName));
                    }
                });
                iApp.Factory.StopBlockingUserInput();
            });
        }
Пример #7
0
        public Image LoadSprite(String FileName, Color ColorKey, float Alpha)
        {
            Image original = Image.FromFile(FileName);
            Image output   = new Bitmap(original.Width, original.Height);

            using (Graphics g = Graphics.FromImage(output))
            {
                ImageAttributes attr       = new ImageAttributes();
                Point[]         pointArray =
                {
                    new Point(0,              0),
                    new Point(original.Width, 0),
                    new Point(0,              original.Height)
                };
                float[][] ptsArray =
                {
                    new float[] { 1, 0, 0,     0, 0 },
                    new float[] { 0, 1, 0,     0, 0 },
                    new float[] { 0, 0, 1,     0, 0 },
                    new float[] { 0, 0, 0, Alpha, 0 }, //注意:此处为0.5f,图像为半透明
                    new float[] { 0, 0, 0,     0, 1 }
                };
                ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
                attr.SetColorKey(ColorKey, ColorKey);
                attr.SetColorMatrix(clrMatrix);
                g.DrawImage(original, pointArray, Rectangle.FromLTRB(0, 0, original.Width, original.Height), GraphicsUnit.Pixel, attr);
            }

            return(output);
        }
Пример #8
0
        protected static void DrawImage(Graphics graphics, Image image, Rectangle destinationRectangle, Rectangle sourceRectangle)
        {
            /*
             * The only place where some porting issues arises in when drawing images, because of this the
             * ProgressBar code does not draw using Graphics.DrawImage directly. It instead uses this
             * wrapper method that takes care of any porting issues using pre-processor directives.
             */

#if WIN32
            //
            // The .NET Compact Framework can not handle transparent pngs (or any images), so to achieve
            // transparancy we need to set the image attributes when drawing the image.
            // I've decided to hard code the "chroma key" value to Color.Magenta but that can easily
            // be set by a property instead.
            //
            if (imageAttributes == null)
            {
                imageAttributes = new ImageAttributes();
                imageAttributes.SetColorKey(Color.Magenta, Color.Magenta);
            }

            graphics.DrawImage(image, destinationRectangle, sourceRectangle.X, sourceRectangle.Y, sourceRectangle.Width, sourceRectangle.Height, GraphicsUnit.Pixel, imageAttributes);
#else
            graphics.DrawImage(image, destinationRectangle, sourceRectangle, GraphicsUnit.Pixel);
#endif
        }
Пример #9
0
        /// <summary>
        /// Devuelve una imagen de la mascota con el ancho y el alto especificado.
        /// </summary>
        /// <param name="ancho">Ancho de la imagen.</param>
        /// <param name="alto">Alto de la imagen.</param>
        /// <param name="color">El color que se usará como fondo.</param>
        /// <returns>Imagen de la mascota.</returns>
        public Bitmap GenerarImagenMascota(int ancho, int alto, Color color)
        {
            NodoComponente  aux               = componentes.Cab;
            ImageAttributes atributos         = new ImageAttributes();
            Color           colorTransparente = ((Bitmap)ListaImagenes[0]).GetPixel(0, 0);

            atributos.SetColorKey(colorTransparente, colorTransparente);

            Bitmap   imagen   = new Bitmap(ancho, alto);
            Graphics pintador = Graphics.FromImage(imagen);

            pintador.Clear(color);

            int i = 0;

            while (aux != null)
            {
                Bitmap    dibujo  = (Bitmap)ListaImagenes[i];
                Rectangle destino = new Rectangle(ancho / 2 + aux.Info.DatoComponente.DistanciaPuntoReferencia.X, alto + aux.Info.DatoComponente.DistanciaPuntoReferencia.Y + 20, aux.Info.DatoComponente.RectanguloFuente.Width, aux.Info.DatoComponente.RectanguloFuente.Height);
                pintador.DrawImage(dibujo, destino, aux.Info.DatoComponente.RectanguloFuente.X, aux.Info.DatoComponente.RectanguloFuente.Y, aux.Info.DatoComponente.RectanguloFuente.Width, aux.Info.DatoComponente.RectanguloFuente.Height, GraphicsUnit.Pixel, atributos);
                aux = aux.Siguiente;
                i++;
            }

            return(imagen);
        }
Пример #10
0
        protected static void DrawIcon(Graphics graphics, Image imgPanelIcon, Rectangle imageRectangle, Color foreColorImage, int iconPositionY)
        {
            if (graphics == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Resources.IDS_ArgumentException, new object[1]
                {
                    typeof(Graphics).Name
                }));
            }
            if (imgPanelIcon == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Resources.IDS_ArgumentException, new object[1]
                {
                    typeof(Image).Name
                }));
            }
            int       left     = imageRectangle.Left;
            int       width    = imgPanelIcon.Width;
            int       height   = imgPanelIcon.Height;
            Rectangle destRect = new Rectangle(left + width / 2 - 1, iconPositionY + height / 2 - 1, imgPanelIcon.Width, imgPanelIcon.Height - 1);

            using (ImageAttributes imageAttributes = new ImageAttributes())
            {
                imageAttributes.SetColorKey(Color.Magenta, Color.Magenta);
                ColorMap colorMap = new ColorMap();
                colorMap.OldColor = Color.FromArgb(0, 60, 166);
                colorMap.NewColor = foreColorImage;
                imageAttributes.SetRemapTable(new ColorMap[1]
                {
                    colorMap
                });
                graphics.DrawImage(imgPanelIcon, destRect, 0, 0, width, height, GraphicsUnit.Pixel, imageAttributes);
            }
        }
Пример #11
0
        private void PaintScrollBarSolid(Graphics g, Rectangle bounds)
        {
            ImageAttributes ia = new ImageAttributes();

            ia.SetColorKey(Color.Fuchsia, Color.Fuchsia);
            g.DrawImage(scrollBarButton, bounds, 0, 0, bounds.Width, bounds.Height, GraphicsUnit.Pixel, ia);
        }
        private static void DrawImage(Graphics graphics, Image image, bool setTransparentColor, Rectangle bounds)
        {
            var bitmap = image as Bitmap;

            if (bitmap == null)
            {
                return;
            }

            var factor = 1.0;

            if (bitmap.Height > bounds.Height && bounds.Height > 0)
            {
                factor = (double)bounds.Height / (double)bitmap.Height;
            }

            var width  = (int)(bitmap.Width * factor + 0.5);
            var height = (int)(bitmap.Height * factor + 0.5);

            var bitmapRect = new Rectangle(bounds.X, bounds.Y + (bounds.Height - height) / 2, width, height);

            if (setTransparentColor)
            {
                using (var ia = new ImageAttributes())
                {
                    var color = bitmap.GetPixel(0, 0);
                    ia.SetColorKey(color, color);
                    graphics.DrawImage(bitmap, bitmapRect, 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel, ia);
                }
            }
            else
            {
                graphics.DrawImage(bitmap, bitmapRect, 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel);
            }
        }
Пример #13
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            Bitmap img = (this.IsMouseDown) ? this.DownImage : ((this.IsSelected) ? this.SelectedImage : this.Image);

            if (_willSelect)
            {
                img = this.SelectedImage;
            }

            ImageAttributes attributes = new ImageAttributes();

            using (Bitmap bmp = new Bitmap(this.Width, this.Height))
            {
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    if (this.TransparentBackground)
                    {
                        g.Clear(_backColor);

                        Color clr = img.GetPixel(0, 0);
                        attributes.SetColorKey(clr, clr);
                    }
                    g.DrawImage(img, this.ClientRectangle, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, attributes);
                }
                e.Graphics.DrawImage(bmp, 0, 0);
            }
        }
Пример #14
0
        protected void DrawGapChkMark(Graphics g, double scale)
        {
            ImageAttributes ia = new ImageAttributes();

            ia.SetColorKey(Color.White, Color.White);
            Image     bmpMark = Properties.Resources.imageGapChkMark;
            int       width   = bmpMark.Width;
            int       height  = bmpMark.Height;
            Rectangle rc      = new Rectangle(0, 0, width, height);

            foreach (Point pt in document.GapChkResult)
            {
                Point ptD = RealToDraw(pt, scale);
                rc.X = ptD.X - 15;
                rc.Y = ptD.Y - 31;
                g.DrawImage(bmpMark, rc, 0, 0, width, height, GraphicsUnit.Pixel, ia);
            }



            //if (gapChkMarkIcon == null) {
            //    gapChkMarkIcon = new Icon(Properties.Resources.GapChkMarkIcon, 32, 32);
            //}
            //foreach (Point pt in document.GapChkResult) {
            //    Point ptD = RealToDraw(pt, scale);
            //    g.DrawIcon(gapChkMarkIcon, ptD.X - 15, ptD.Y - 31);
            //}
        }
Пример #15
0
        private static void MakeTransparent(string p)
        {
            FileStream   fs = new FileStream(p, FileMode.Open, FileAccess.Read);
            MemoryStream ms = new MemoryStream();

            fs.CopyTo(ms);
            ms.Position = 0;
            fs.Close();
            using (Image original = new Bitmap(ms))
            {
                using (Bitmap image = new Bitmap(original.Width, original.Height, PixelFormat.Format32bppArgb))
                {
                    Graphics        g  = Graphics.FromImage(image);
                    ImageAttributes ia = new ImageAttributes();
                    ia.SetColorKey(Color.FromArgb(0, 0xde, 0), Color.FromArgb(33, 255, 5));
                    g.DrawImage(
                        original,
                        new Rectangle(0, 0, original.Width, original.Height),
                        0,
                        0,
                        original.Width,
                        original.Height,
                        GraphicsUnit.Pixel,
                        ia);
                    image.Save(p, ImageFormat.Png);
                    g.Dispose();
                    ia.Dispose();
                }
            }
        }
Пример #16
0
        internal void DrawPlusMinus(Graphics g)
        {
            if (!IsInATreeListView)
            {
                return;
            }
            if (TreeListView._Updating)
            {
                return;
            }
            if (Items.Count == 0 || TreeListView.Columns.Count == 0)
            {
                return;
            }

            using (ImageAttributes attr = new ImageAttributes())
            {
                attr.SetColorKey(Color.Transparent, Color.Transparent);
                if (TreeListView.Columns[0].Width > (Level + 1) * SystemInformation.SmallIconSize.Width)
                {
                    g.DrawImage(
                        IsExpanded ?Properties.Resources.Collapse1:Properties.Resources.Expand1,
                        GetBounds(TreeListViewItemBoundsPortion.PlusMinus),
                        0,
                        0,
                        SystemInformation.SmallIconSize.Width,
                        SystemInformation.SmallIconSize.Height,
                        GraphicsUnit.Pixel,
                        attr);
                }
            }
        }
Пример #17
0
        public ShapeObject(LayerManager layerManager, String filePath)
        {
            this._layerType  = LayerType.Shape;
            this.Description = "ESRI Shapedatei";
            this.Changed     = this.Visible = true;

            this.layerManager = layerManager;
            this.LayerInfo    = new LayerInfo(filePath);
            this.access       = "rb";
            Color tempColor = layerManager.NewLayerStyle.NewColor;

            this.vectorInfo = new VectorInfo(tempColor, Color.White, new Pen(tempColor, 1.0f));
            this.m_filePath = System.IO.Path.GetDirectoryName(filePath);
            this.m_fileName = System.IO.Path.GetFileNameWithoutExtension(filePath);

            int i = filePath.LastIndexOf("\\");

            this.LayerName = filePath.Substring(i + 1,
                                                filePath.LastIndexOf(".") - i - 1);

            // new InmageAttributes
            imageAttributes = new ImageAttributes();
            imageAttributes.SetColorKey(Color.NavajoWhite, Color.NavajoWhite);
            bitmap = new Bitmap(1, 1, PixelFormat.Format16bppRgb555);
        }
Пример #18
0
        private void drawPanel_Paint(object sender, PaintEventArgs e)
        {
            Image smallImage = Resources.Elements_Small;
            Image largeImage = Resources.Elements_Large;

            //draw normally
            e.Graphics.DrawImage(smallImage, 10, 10);

            //draw resized--interpolating pixels
            e.Graphics.InterpolationMode = _interpolationMode;
            e.Graphics.DrawImage(smallImage, 250, 100, 400, 400);

            //draw a subsection
            var sourceRect = new Rectangle(400, 400, 200, 200);
            var destRect   = new Rectangle(10, 200, sourceRect.Width, sourceRect.Height);

            e.Graphics.DrawImage(Resources.Elements_Large, destRect, sourceRect, GraphicsUnit.Pixel);

            //draw same subsection with black as transparent
            var imageAttributes = new ImageAttributes();

            imageAttributes.SetColorKey(Color.Black, Color.Black, ColorAdjustType.Bitmap);
            destRect.Offset(200, 150);
            e.Graphics.DrawImage(largeImage, destRect, sourceRect.X, sourceRect.Y,
                                 sourceRect.Width, sourceRect.Height, GraphicsUnit.Pixel, imageAttributes);
        }
Пример #19
0
 public void RenderTopImage(GaugeGraphics g)
 {
     if (base.TopImage != "")
     {
         ImageAttributes imageAttributes = new ImageAttributes();
         if (base.TopImageTransColor != Color.Empty)
         {
             imageAttributes.SetColorKey(base.TopImageTransColor, base.TopImageTransColor, ColorAdjustType.Default);
         }
         Image     image    = this.Common.ImageLoader.LoadImage(base.TopImage);
         Rectangle destRect = Rectangle.Round(g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f)));
         if (!base.TopImageHueColor.IsEmpty)
         {
             Color       color       = g.TransformHueColor(base.TopImageHueColor);
             ColorMatrix colorMatrix = new ColorMatrix();
             colorMatrix.Matrix00 = (float)((float)(int)color.R / 255.0);
             colorMatrix.Matrix11 = (float)((float)(int)color.G / 255.0);
             colorMatrix.Matrix22 = (float)((float)(int)color.B / 255.0);
             imageAttributes.SetColorMatrix(colorMatrix);
         }
         ImageSmoothingState imageSmoothingState = new ImageSmoothingState(g);
         imageSmoothingState.Set();
         g.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
         imageSmoothingState.Restore();
     }
 }
Пример #20
0
        private void SetColorKey_Click(object sender,
                                       System.EventArgs e)
        {
            Graphics g = this.CreateGraphics();

            g.Clear(this.BackColor);

            Color           lClr    = Color.FromArgb(245, 0, 0);
            Color           uClr    = Color.FromArgb(255, 0, 0);
            ImageAttributes ImgAttr = new ImageAttributes();

            ImgAttr.SetColorKey(lClr, uClr, ColorAdjustType.Default);

            // Open an Image file and draw it to the screen.
            Image curImage = Image.FromFile("dnWatcher.gif");

            g.DrawImage(curImage, 0, 0);
            // Draw the image with the color key set.
            Rectangle rect = new Rectangle(0, 0, 400, 400);

            g.DrawImage(curImage, rect, 0, 0, 400, 400,
                        GraphicsUnit.Pixel, ImgAttr);

            // Dispose
            g.Dispose();
        }
Пример #21
0
        private void PieceInfoControl_Paint(object sender, PaintEventArgs e)
        {
            //	Draw miniature piece
            if (BoardPresentation != null)
            {
                BoardPresentation.PieceSetPresentation.Render(e.Graphics,
                                                              new Rectangle(102, 27, 0, 0), Piece);
            }

            Bitmap       target  = Properties.Resources.target;
            ColorPalette palette = target.Palette;

            for (int x = 0; x < palette.Entries.Length; x++)
            {
                if (palette.Entries[x] == Color.FromArgb(0, 255, 0))
                {
                    palette.Entries[x] = Color.FromArgb(1, 0, 0);
                }
            }
            ImageAttributes attr = new ImageAttributes();

            attr.SetColorKey(target.GetPixel(0, 0), target.GetPixel(0, 0));
            e.Graphics.DrawImage(target, new Rectangle(-16, 15, target.Width, target.Height),
                                 0, 0, target.Width, target.Height, GraphicsUnit.Pixel, attr);
        }
Пример #22
0
        private void SetNoOp_Click(object sender,
                                   System.EventArgs e)
        {
            // Create a Graphics object
            Graphics g = this.CreateGraphics();

            g.Clear(this.BackColor);
            // Create two colors
            Color lClr = Color.FromArgb(245, 0, 0);
            Color uClr = Color.FromArgb(255, 0, 0);
            // Create ImageAttributes object
            ImageAttributes ImgAttr = new ImageAttributes();

            // Set ColorKey
            ImgAttr.SetColorKey(lClr, uClr,
                                ColorAdjustType.Default);
            // Set gamma
            ImgAttr.SetGamma(2.0f, ColorAdjustType.Default);
            // Set NoOp
            ImgAttr.SetNoOp(ColorAdjustType.Default);
            // Create an Image object
            Image curImage = Image.FromFile("dnWatcher.gif");
            // Draw Image
            Rectangle rect = new Rectangle(0, 0, 400, 400);

            g.DrawImage(curImage, rect, 0, 0, 400, 400,
                        GraphicsUnit.Pixel, ImgAttr);
            // Dispose
            g.Dispose();
        }
Пример #23
0
        private ImageAttributes GetWatermarkImageAttributes(int imageOpacityPercent)
        {
            // Change the opacity of the watermark.  This is done by applying a 5x5 matrix that contains the
            // coordinates for the RGBA space.  Set the 3rd row and 3rd column to the desired opacity. (0.0 - 1.0).

            if (_imageAttributes != null)
            {
                return(_imageAttributes);
            }

            float opacity = imageOpacityPercent / 100.0f;

            float[][] colorMatrixElements =
            {
                new float[] { 1.0f, 0.0f, 0.0f,    0.0f, 0.0f },
                new float[] { 0.0f, 1.0f, 0.0f,    0.0f, 0.0f },
                new float[] { 0.0f, 0.0f, 1.0f,    0.0f, 0.0f },
                new float[] { 0.0f, 0.0f, 0.0f, opacity, 0.0f },
                new float[] { 0.0f, 0.0f, 0.0f,    0.0f, 1.0f }
            };
            ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);

            _imageAttributes = new ImageAttributes();
            _imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Default);
            _imageAttributes.SetColorKey(Color.Transparent, Color.Transparent);

            return(_imageAttributes);
        }
Пример #24
0
        protected void PaintClient(Object sender, PaintEventArgs e)
        {
            try
            {
                Form frm = sender as Form;
                e.Graphics.Clip = new Region(frm.ClientRectangle);
                //
                //        LinearGradientBrush lgb = new LinearGradientBrush(frm.ClientRectangle, Color.LightBlue, Color.FromArgb(0,0,160), 90F, false);
                //        e.Graphics.FillRectangle(lgb, frm.ClientRectangle);
                //        lgb.Dispose();

                PictureBox pic = pictureLogo;

                if (pic.Image != null)
                {
                    Rectangle rect    = pic.ClientRectangle;
                    Rectangle imgRect = new Rectangle(pic.Left, pic.Top, pic.Width, pic.Height);

                    ImageAttributes imageAttributes = new ImageAttributes();
                    imageAttributes.SetColorKey(Color.FromArgb(220, 220, 220), Color.White, ColorAdjustType.Bitmap);

                    e.Graphics.DrawImage(pic.Image, imgRect, 0, 0, rect.Width, rect.Height, GraphicsUnit.Pixel, imageAttributes);
                }
            }

            catch (Exception ex)
            {
                Debug.Fail(ex.Message, "frmAbout.PaintClient");
            }
        }
Пример #25
0
        protected virtual void OnRenderItemImage(ToolStripItemImageRenderEventArgs e)
        {
            bool  need_dispose = false;
            Image i            = e.Image;

            if (e.Item.RightToLeft == RightToLeft.Yes && e.Item.RightToLeftAutoMirrorImage == true)
            {
                i            = CreateMirrorImage(i);
                need_dispose = true;
            }

            if (e.Item.ImageTransparentColor != Color.Empty)
            {
                ImageAttributes ia = new ImageAttributes();
                ia.SetColorKey(e.Item.ImageTransparentColor, e.Item.ImageTransparentColor);
                e.Graphics.DrawImage(i, e.ImageRectangle, 0, 0, i.Width, i.Height, GraphicsUnit.Pixel, ia);
                ia.Dispose();
            }
            else
            {
                e.Graphics.DrawImage(i, e.ImageRectangle);
            }

            if (need_dispose)
            {
                i.Dispose();
            }

            ToolStripItemImageRenderEventHandler eh = (ToolStripItemImageRenderEventHandler)Events [RenderItemImageEvent];

            if (eh != null)
            {
                eh(this, e);
            }
        }
Пример #26
0
            protected override void OnPaint(PaintEventArgs e)
            {
                Color foreColor = SystemColors.ControlText;

                if (this.Selected)
                {
                    foreColor = SystemColors.HighlightText;
                    e.Graphics.DrawImage(this.SelectedImage, this.ClientRectangle, new Rectangle(0, 0, this.SelectedImage.Width, this.SelectedImage.Height), GraphicsUnit.Pixel);
                }
                else
                {
                    e.Graphics.DrawImage(this.RegularImage, this.ClientRectangle, new Rectangle(0, 0, this.RegularImage.Width, this.RegularImage.Height), GraphicsUnit.Pixel);
                }

                if (this.MenuItem.MenuItems.Count > 0)
                {
                    ImageAttributes attributes = new ImageAttributes();

                    Color clr = this.ExpandImage.GetPixel(0, 0);
                    attributes.SetColorKey(clr, clr);
                    e.Graphics.DrawImage(this.ExpandImage, new Rectangle(this.Right - this.ExpandImage.Width - 5, (this.Height - this.ExpandImage.Height) / 2, this.ExpandImage.Width, this.ExpandImage.Height), 0, 0, this.ExpandImage.Width, this.ExpandImage.Height, GraphicsUnit.Pixel, attributes);
                }

                using (SolidBrush b = new SolidBrush(this.Parent.ForeColor))
                {
                    SizeF size = e.Graphics.MeasureString(this.Text, this.Font);
                    e.Graphics.DrawString(this.Text, this.Font, b, 20, (this.Height - size.Height) / 2);
                }
            }
Пример #27
0
        private void OnMapNewTileAvaliable(TileInfo tileInfo, Bitmap bitmap)
        {
            if (_onlyRedrawWhenComplete)
            {
                return;
            }

            if (MapNewTileAvaliable != null)
            {
                var bb = new Envelope(new Coordinate(tileInfo.Extent.MinX, tileInfo.Extent.MinY), new Coordinate(tileInfo.Extent.MaxX, tileInfo.Extent.MaxY));
                using (var ia = new ImageAttributes())
                {
                    if (!_transparentColor.IsEmpty)
                    {
                        ia.SetColorKey(_transparentColor, _transparentColor);
                    }
                    ia.SetColorMatrix(new ColorMatrix {
                        Matrix33 = _opacity
                    }, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
#if !PocketPC
                    ia.SetWrapMode(WrapMode.TileFlipXY);
#endif
                    var tileWidth  = _source.Schema.GetTileWidth(tileInfo.Index.Level);
                    var tileHeight = _source.Schema.GetTileHeight(tileInfo.Index.Level);
                    MapNewTileAvaliable(this, bb, bitmap, tileWidth, tileHeight, ia);
                }
            }
        }
Пример #28
0
        /// <summary>
        /// Returns the image of the gradient filled rounded rectangle
        /// </summary>
        /// <param name="rc">Desctination rectangle</param>
        /// <param name="startColorValue">Starting color for gradient</param>
        /// <param name="endColorValue">End color for gradient</param>
        /// <param name="borderColor">The color of the border</param>
        /// <param name="size">The size of the rounded corners</param>
        /// <returns>Bitmap image</returns>
        public static Bitmap GetGradiendRoundedRectangle(Rectangle rc, Color startColorValue, Color endColorValue, Color borderColor, Size size)
        {
            Bitmap outputImage = new Bitmap(rc.Width, rc.Height);
            // Create temporary graphics
            Graphics gx = Graphics.FromImage(outputImage);

            GradientFill.Fill(
                gx,
                rc,
                startColorValue,
                endColorValue,
                FillDirection.TopToBottom);

            Rectangle roundedRect = rc;

            roundedRect.Width--;
            roundedRect.Height--;

            Bitmap borderImage = ImposeRoundedRectangle(roundedRect, borderColor, size);

            ImageAttributes attrib = new ImageAttributes();

            attrib.SetColorKey(Color.Green, Color.Green);

            gx.DrawImage(borderImage, rc, 0, 0, borderImage.Width, borderImage.Height, GraphicsUnit.Pixel, attrib);

            // Clean up
            attrib.Dispose();
            gx.Dispose();

            return(outputImage);
        }
Пример #29
0
        public static void DrawRoundedBorder(this Graphics g, Color color, Rectangle rec,
                                             int radius, int borderWidth)
        {
            using (Bitmap b = new Bitmap(rec.Width, rec.Height))
            {
                using (Graphics gb = Graphics.FromImage(b))
                {
                    var gfRec = new Rectangle(0, 0, rec.Width, rec.Height);
                    gb.Clear(Color.Green);

                    gb.DrawRoundedRectangle(color, gfRec, radius);

                    gfRec.Height -= borderWidth << 1;
                    gfRec.Width  -= borderWidth << 1;
                    gfRec.X      += borderWidth;
                    gfRec.Y      += borderWidth;
                    gb.DrawRoundedRectangle(Color.Green, gfRec, radius - borderWidth);

                    var maskAttr = new ImageAttributes();
                    maskAttr.SetColorKey(Color.Green, Color.Green);

                    g.DrawImage(b, rec, 0, 0, b.Width, b.Height, GraphicsUnit.Pixel, maskAttr);
                }
            }
        }
Пример #30
0
        private void OnMapNewTileAvaliable(TileInfo tileInfo, byte[] bitmap)
        {
            if (_onlyRedrawWhenComplete)
            {
                return;
            }

            if (MapNewTileAvaliable != null)
            {
                var bb = new Envelope(new Coordinate(tileInfo.Extent.MinX, tileInfo.Extent.MinY), new Coordinate(tileInfo.Extent.MaxX, tileInfo.Extent.MaxY));
                using (var ia = new ImageAttributes())
                {
                    if (!_transparentColor.IsEmpty)
                    {
                        ia.SetColorKey(_transparentColor, _transparentColor);
                    }
#if !PocketPC
                    ia.SetWrapMode(WrapMode.TileFlipXY);
#endif
                    if (Opacity < 1.0f)
                    {
                        var matrix = new ColorMatrix {
                            Matrix33 = Math.Max(Math.Min(1f, Opacity), 0f)
                        };
                        ia.SetColorMatrix(matrix);
                    }

                    var tileWidth  = _source.Schema.GetTileWidth(tileInfo.Index.Level);
                    var tileHeight = _source.Schema.GetTileHeight(tileInfo.Index.Level);
                    MapNewTileAvaliable(this, bb, bitmap, tileWidth, tileHeight, ia);
                }
            }
        }