Example #1
0
        private void SetBrushRemapTable_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);

            ColorMap[] clrMapTable = new ColorMap[1];
            clrMapTable[0]          = new ColorMap();
            clrMapTable[0].OldColor = lClr;
            clrMapTable[0].NewColor = uClr;
            ImageAttributes ImgAttr = new ImageAttributes();

            ImgAttr.SetBrushRemapTable(clrMapTable);

            Image curImage = Image.FromFile(@"f:\dnWatcher.gif");

            g.DrawImage(curImage, 0, 0);
            Rectangle rect = new Rectangle(0, 0, 400, 400);

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

            // Dispose
            g.Dispose();
        }
Example #2
0
        /// <summary>
        /// 添加图片水印
        /// </summary>
        /// <param name="p_imageFile">图像文件</param>
        /// <param name="p_saveFile">图像保存路径</param>
        /// <param name="p_SimageFile">水印图片文件</param>
        /// <param name="p_position">水印位置</param>
        /// <param name="p_Transparent">透明度</param>
        public void WaterMark(string p_ImageFile, string p_saveFile, string p_SimageFile, int p_position, int p_Transparent)
        {
            Image p_imageFile    = new Bitmap(p_ImageFile);
            int   originalWidth  = p_imageFile.Width;
            int   originalHeight = p_imageFile.Height;

            using (Image newImage = new Bitmap(p_imageFile))
            {
                Graphics g         = Graphics.FromImage(newImage);
                Image    SnewImage = new Bitmap(p_SimageFile);
                if (SnewImage.Height < originalHeight && SnewImage.Width < originalWidth)
                {
                    ImageAttributes Property = new ImageAttributes();
                    ColorMap        Mapping  = new ColorMap();
                    Mapping.OldColor = Color.FromArgb(255, 0, 0, 0);
                    Mapping.NewColor = Color.FromArgb(0, 0, 0, 0);
                    Property.SetBrushRemapTable(new ColorMap[] { Mapping });

                    float Transparent = 0.5F;
                    if (p_Transparent >= 1 && p_Transparent <= 10)
                    {
                        Transparent = p_Transparent / 10.0F;
                    }

                    float[][] MatrixNode =
                    {
                        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, Transparent, 0.0f },
                        new float[] { 0.0f, 0.0f, 0.0f,        0.0f, 1.0f }
                    };
                    ColorMatrix Matrix = new ColorMatrix(MatrixNode);
                    Property.SetColorMatrix(Matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                    int x = 0;
                    int y = 0;
                    //水印位置
                    getImageST(p_position, originalWidth, originalHeight, SnewImage.Width, SnewImage.Height, out x, out y);
                    //绘图
                    g.DrawImage(SnewImage, new Rectangle(x, y, SnewImage.Width, SnewImage.Height), 0, 0, SnewImage.Width, SnewImage.Height, GraphicsUnit.Pixel, Property);
                    p_imageFile.Dispose();
                    SnewImage.Dispose();
                    g.Dispose();
                    if (string.IsNullOrEmpty(p_saveFile))
                    {
                        newImage.Save(p_ImageFile, ImageFormat.Jpeg);
                    }
                    else
                    {
                        newImage.Save(p_saveFile, ImageFormat.Jpeg);
                    }
                }
            }
        }
Example #3
0
        // Snippet for: M:System.Drawing.Imaging.ImageAttributes.SetBrushRemapTable(System.Drawing.Imaging.ColorMap[])
        // <snippet1>
        public void SetBrushRemapTableExample(PaintEventArgs e)
        {
            // Create a color map.
            ColorMap[] myColorMap = new ColorMap[1];
            myColorMap[0]          = new ColorMap();
            myColorMap[0].OldColor = Color.Red;
            myColorMap[0].NewColor = Color.Green;

            // Create an ImageAttributes object, passing it to the myColorMap

            // array.
            ImageAttributes imageAttr = new ImageAttributes();

            imageAttr.SetBrushRemapTable(myColorMap);
        }
Example #4
0
        private void SetBrushRemapTable_Click(object sender,
                                              System.EventArgs e)
        {
            Graphics g = this.CreateGraphics();

            g.Clear(this.BackColor);
            ColorMap[] clrMapTable = new ColorMap[1];
            clrMapTable[0]          = new ColorMap();
            clrMapTable[0].OldColor = Color.Red;;
            clrMapTable[0].NewColor = Color.Green;
            ImageAttributes ImgAttr = new ImageAttributes();

            ImgAttr.SetBrushRemapTable(clrMapTable);
            Image curImage = Image.FromFile("Sample.bmp");

            g.DrawImage(curImage, 0, 0);
            Rectangle rect = new Rectangle(0, 0, 400, 400);

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