コード例 #1
0
ファイル: Helpers.cs プロジェクト: olehgerus/Watermarking
        /// <summary>
        /// Set brightness for the image
        /// </summary>
        /// <param name="image">input bitmap</param>
        /// <param name="value">value from -255 to 255</param>
        /// <returns></returns>
        public static Bitmap SetBrightness(Bitmap image, int value)
        {
            var tempBitmap  = image;
            var finalValue  = value / 255.0f;
            var newBitmap   = new Bitmap(tempBitmap.Width, tempBitmap.Height);
            var newGraphics = Graphics.FromImage(newBitmap);

            float[][] floatColorMatrix =
            {
                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, 1, 0 },
                new[]       { finalValue, finalValue, finalValue, 1, 1 }
            };

            var newColorMatrix = new System.Drawing.Imaging.ColorMatrix(floatColorMatrix);
            var attributes     = new System.Drawing.Imaging.ImageAttributes();

            attributes.SetColorMatrix(newColorMatrix);
            newGraphics.DrawImage(tempBitmap, new System.Drawing.Rectangle(0, 0, tempBitmap.Width, tempBitmap.Height), 0, 0, tempBitmap.Width, tempBitmap.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
            attributes.Dispose();
            newGraphics.Dispose();
            return(newBitmap);
        }
コード例 #2
0
ファイル: TreeListViewItem.cs プロジェクト: utobe/QuickMon
 internal void DrawPlusMinus(Graphics g)
 {
     if (!IsInATreeListView)
     {
         return;
     }
     if (TreeListView._updating)
     {
         return;
     }
     Debug.Assert(!TreeListView.InvokeRequired);
     if (Items.Count == 0 || TreeListView.Columns.Count == 0)
     {
         return;
     }
     System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
     attr.SetColorKey(Color.Transparent, Color.Transparent);
     if (TreeListView.Columns[0].Width > (Level + 1) * SystemInformation.SmallIconSize.Width)
     {
         g.DrawImage(
             TreeListView.plusMinusImageList.Images[IsExpanded ? 1 : 0],
             GetBounds(TreeListViewItemBoundsPortion.PlusMinus),
             0, 0, SystemInformation.SmallIconSize.Width, SystemInformation.SmallIconSize.Height,
             GraphicsUnit.Pixel, attr);
     }
     attr.Dispose();
 }
コード例 #3
0
        //this function is not entirely from me:
        public Bitmap AdjustBrightnessMatrix(Bitmap img, float RedMul, float GreenMul, float BlueMul)
        {
            //if (value == 0) { return img; } // No change, so just return

            //System.Drawing.Imaging.ColorMap cmm = new System.Drawing.Imaging.ColorMap();



            //float sb = (float)value / 255F;
            //float d = 1f / sb;
            float[][] colorMatrixElements =
            {
                new float[] { RedMul,        0,       0, 0, 0 }, //new float[] {1,  0,  0,  0, 0},
                new float[] {      0, GreenMul,       0, 0, 0 }, //new float[] {0,  1,  0,  0, 0},
                new float[] {      0,        0, BlueMul, 0, 0 }, //new float[] {0,  0,  1,  0, 0},
                new float[] {      0,        0,       0, 1, 0 }, //new float[] {0,  0,  0,  1, 0},
                new float[] {      0,        0,       0, 1, 0 }  //new float[] {sb, sb, sb, 1, 1}
            };

            System.Drawing.Imaging.ColorMatrix     cm      = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);
            System.Drawing.Imaging.ImageAttributes imgattr = new System.Drawing.Imaging.ImageAttributes();
            System.Drawing.Rectangle rc = new System.Drawing.Rectangle(0, 0, img.Width, img.Height);
            System.Drawing.Graphics  g  = System.Drawing.Graphics.FromImage(img);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            imgattr.SetColorMatrix(cm);
            g.DrawImage(img, rc, 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel, imgattr);

            imgattr.Dispose();
            g.Dispose();
            return(img);
        }
コード例 #4
0
        // 添加图片水印
        public static string addWaterMark(string filepath, string fileName)
        {
            System.Drawing.Image image = System.Drawing.Image.FromFile(filepath + fileName);
            Bitmap   b = new Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Graphics g = Graphics.FromImage(b);

            g.Clear(Color.White);
            g.DrawImage(image, 0, 0, image.Width, image.Height);

            Image watermark = new Bitmap(AppDomain.CurrentDomain.BaseDirectory + @"Content/image/logo.png");

            System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
            System.Drawing.Imaging.ColorMap        colorMap        = new System.Drawing.Imaging.ColorMap();
            colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
            System.Drawing.Imaging.ColorMap[] remapTable = { colorMap };
            imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap);
            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, 0.3f, 0.0f },
                new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
            };
            System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);
            imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);
            int xpos = 0;
            int ypos = 0;

            xpos = ((image.Width - watermark.Width) / 2);
            ypos = (image.Height - watermark.Height) / 2;

            g.DrawImage(watermark, new Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel, imageAttributes);

            watermark.Dispose();
            imageAttributes.Dispose();


            //保存加水印过后的图片,删除原始图片
            fileName = DateTime.Now.ToFileTime() + new Random().Next(100, 999) + System.IO.Path.GetExtension(fileName);
            b.Save(filepath + fileName);
            b.Dispose();
            image.Dispose();
            if (System.IO.File.Exists(filepath))
            {
                System.IO.File.Delete(filepath);
            }

            return(fileName);
        }
コード例 #5
0
        private void fixDisplay()
        {
            Bitmap   b = new Bitmap(mImage.Width, mImage.Height);
            Graphics g = Graphics.FromImage(b);

            System.Drawing.Imaging.ColorMatrix mCM = new System.Drawing.Imaging.ColorMatrix();

            // w
            mCM.Matrix44 = 1.00f;

            if (!rChk.Checked)
            {
                mCM.Matrix00 = 0.00f;
            }

            if (!gChk.Checked)
            {
                mCM.Matrix11 = 0.00f;
            }

            if (!bChk.Checked)
            {
                mCM.Matrix22 = 0.00f;
            }

            //turn alpha off by adding 1 to alpha value
            if (!aChk.Checked)
            {
                mCM.Matrix43        = 1.00f;
                invertAlpha.Enabled = false;
            }
            else
            {
                invertAlpha.Enabled = true;
            }

            System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();


            attr.SetColorMatrix(mCM);

            g.DrawImage(mImage, new Rectangle(0, 0, mImage.Width, mImage.Height),
                        0, 0, mImage.Width, mImage.Height,
                        System.Drawing.GraphicsUnit.Pixel,
                        attr);
            attr.Dispose();

            g.Dispose();

            pictureBox1.Image = b;
        }
コード例 #6
0
        System.Drawing.Bitmap AdjustContrastBrightnessMatrix(System.Drawing.Bitmap img, int cont, int brite)
        {
            if (cont == 0 && brite == 0) // No change, so just return
            {
                return(img);
            }

            float c       = (float)(100 + cont) / 100F;
            float t       = (1F - c) / 2F;
            float sb      = (float)brite / 255F;
            float sb_help = 0;

            if (sb != 0)
            {
                sb_help = 1F;
            }

            float[][] colorMatrixElements =
            {
                new float[] { c,           0,      0,       0, 0 },
                new float[] {      0, c,           0,       0, 0 },
                new float[] {      0,      0, c,            0, 0 },
                new float[] {      0,      0,      0,       1, 0 },
                new float[] { t + sb, t + sb, t + sb, sb_help, 1 }
            };

            System.Drawing.Imaging.ColorMatrix     cm      = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);
            System.Drawing.Imaging.ImageAttributes imgattr = new System.Drawing.Imaging.ImageAttributes();
            System.Drawing.Rectangle rc = new System.Drawing.Rectangle(0, 0, img.Width, img.Height);
            System.Drawing.Graphics  g  = System.Drawing.Graphics.FromImage(img);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            imgattr.SetColorMatrix(cm);
            g.DrawImage(img, rc, 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel, imgattr);

            imgattr.Dispose();
            g.Dispose();
            return(img);
        }
コード例 #7
0
ファイル: ItemButton.cs プロジェクト: tsebalj1/rawr
 private Image GetDimIcon(Image icon)
 {
     try
     {
         Bitmap   original = new Bitmap(icon);
         Bitmap   bmp      = new Bitmap(original.Width, original.Height);
         Graphics g        = Graphics.FromImage(bmp);
         System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
         System.Drawing.Imaging.ColorMatrix     cm = new System.Drawing.Imaging.ColorMatrix();
         cm.Matrix33 = 0.5f;
         ia.SetColorMatrix(cm);
         g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height), 0, 0,
                     original.Width, original.Height, GraphicsUnit.Pixel, ia);
         g.Dispose();
         ia.Dispose();
         original.Dispose();
         return(bmp);
     }
     catch
     {
         return(null);
     }
 }
コード例 #8
0
ファイル: ImageHelp.cs プロジェクト: WZDotCMS/WZDotCMS
        /// <summary>
        /// 加图片水印
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="watermarkFilename">水印文件名</param>
        /// <param name="watermarkStatus">图片水印位置:0=不使用 1=左上 2=中上 3=右上 4=左中 ... 9=右下</param>
        /// <param name="quality">是否是高质量图片 取值范围0--100</param> 
        /// <param name="watermarkTransparency">图片水印透明度 取值范围1--10 (10为不透明)</param>
        public static void AddImageSignPic(string Path, string filename, string watermarkFilename, int watermarkStatus, int quality, int watermarkTransparency)
        {
            System.Drawing.Image img = System.Drawing.Image.FromFile(Path);
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img);

            //设置高质量插值法
            //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
            //设置高质量,低速度呈现平滑程度
            //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            System.Drawing.Image watermark = new System.Drawing.Bitmap(watermarkFilename);

            if (watermark.Height >= img.Height || watermark.Width >= img.Width)
            {
                return;
            }

            System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
            System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap();

            colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0);
            System.Drawing.Imaging.ColorMap[] remapTable = { colorMap };

            imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap);

            float transparency = 0.5F;
            if (watermarkTransparency >= 1 && watermarkTransparency <= 10)
            {
                transparency = (watermarkTransparency / 10.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,  transparency, 0.0f},
                                                new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
                                            };

            System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);

            imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);

            int xpos = 0;
            int ypos = 0;

            switch (watermarkStatus)
            {
                case 1:
                    xpos = (int)(img.Width * (float).01);
                    ypos = (int)(img.Height * (float).01);
                    break;
                case 2:
                    xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                    ypos = (int)(img.Height * (float).01);
                    break;
                case 3:
                    xpos = (int)((img.Width * (float).99) - (watermark.Width));
                    ypos = (int)(img.Height * (float).01);
                    break;
                case 4:
                    xpos = (int)(img.Width * (float).01);
                    ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                    break;
                case 5:
                    xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                    ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                    break;
                case 6:
                    xpos = (int)((img.Width * (float).99) - (watermark.Width));
                    ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                    break;
                case 7:
                    xpos = (int)(img.Width * (float).01);
                    ypos = (int)((img.Height * (float).99) - watermark.Height);
                    break;
                case 8:
                    xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                    ypos = (int)((img.Height * (float).99) - watermark.Height);
                    break;
                case 9:
                    xpos = (int)((img.Width * (float).99) - (watermark.Width));
                    ypos = (int)((img.Height * (float).99) - watermark.Height);
                    break;
            }

            g.DrawImage(watermark, new System.Drawing.Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes);

            System.Drawing.Imaging.ImageCodecInfo[] codecs = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();
            System.Drawing.Imaging.ImageCodecInfo ici = null;
            foreach (System.Drawing.Imaging.ImageCodecInfo codec in codecs)
            {
                //if (codec.MimeType.IndexOf("jpeg") > -1)
                if (codec.MimeType.Contains("jpeg"))
                {
                    ici = codec;
                }
            }
            System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters();
            long[] qualityParam = new long[1];
            if (quality < 0 || quality > 100)
            {
                quality = 80;
            }
            qualityParam[0] = quality;

            System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam);
            encoderParams.Param[0] = encoderParam;

            if (ici != null)
            {
                img.Save(filename, ici, encoderParams);
            }
            else
            {
                img.Save(filename);
            }

            g.Dispose();
            img.Dispose();
            watermark.Dispose();
            imageAttributes.Dispose();
        }
コード例 #9
0
ファイル: ImageHelp.cs プロジェクト: LiuDemin09/QzMes
        /// <summary>
        /// 加图片水印
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="watermarkFilename">水印文件名</param>
        /// <param name="watermarkStatus">图片水印位置:0=不使用 1=左上 2=中上 3=右上 4=左中 ... 9=右下</param>
        /// <param name="quality">是否是高质量图片 取值范围0--100</param>
        /// <param name="watermarkTransparency">图片水印透明度 取值范围1--10 (10为不透明)</param>

        public static void AddImageSignPic(string Path, string filename, string watermarkFilename, int watermarkStatus, int quality, int watermarkTransparency)
        {
            System.Drawing.Image    img = System.Drawing.Image.FromFile(Path);
            System.Drawing.Graphics g   = System.Drawing.Graphics.FromImage(img);

            //设置高质量插值法
            //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
            //设置高质量,低速度呈现平滑程度
            //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            System.Drawing.Image watermark = new System.Drawing.Bitmap(watermarkFilename);

            if (watermark.Height >= img.Height || watermark.Width >= img.Width)
            {
                return;
            }

            System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
            System.Drawing.Imaging.ColorMap        colorMap        = new System.Drawing.Imaging.ColorMap();

            colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0);
            System.Drawing.Imaging.ColorMap[] remapTable = { colorMap };

            imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap);

            float transparency = 0.5F;

            if (watermarkTransparency >= 1 && watermarkTransparency <= 10)
            {
                transparency = (watermarkTransparency / 10.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, transparency, 0.0f },
                new float[] { 0.0f, 0.0f, 0.0f,         0.0f, 1.0f }
            };

            System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);

            imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);

            int xpos = 0;
            int ypos = 0;

            switch (watermarkStatus)
            {
            case 1:
                xpos = (int)(img.Width * (float).01);
                ypos = (int)(img.Height * (float).01);
                break;

            case 2:
                xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                ypos = (int)(img.Height * (float).01);
                break;

            case 3:
                xpos = (int)((img.Width * (float).99) - (watermark.Width));
                ypos = (int)(img.Height * (float).01);
                break;

            case 4:
                xpos = (int)(img.Width * (float).01);
                ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                break;

            case 5:
                xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                break;

            case 6:
                xpos = (int)((img.Width * (float).99) - (watermark.Width));
                ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                break;

            case 7:
                xpos = (int)(img.Width * (float).01);
                ypos = (int)((img.Height * (float).99) - watermark.Height);
                break;

            case 8:
                xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                ypos = (int)((img.Height * (float).99) - watermark.Height);
                break;

            case 9:
                xpos = (int)((img.Width * (float).99) - (watermark.Width));
                ypos = (int)((img.Height * (float).99) - watermark.Height);
                break;
            }

            g.DrawImage(watermark, new System.Drawing.Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes);

            System.Drawing.Imaging.ImageCodecInfo[] codecs = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();
            System.Drawing.Imaging.ImageCodecInfo   ici    = null;
            foreach (System.Drawing.Imaging.ImageCodecInfo codec in codecs)
            {
                //if (codec.MimeType.IndexOf("jpeg") > -1)
                if (codec.MimeType.Contains("jpeg"))
                {
                    ici = codec;
                }
            }
            System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters();
            long[] qualityParam = new long[1];
            if (quality < 0 || quality > 100)
            {
                quality = 80;
            }
            qualityParam[0] = quality;

            System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam);
            encoderParams.Param[0] = encoderParam;

            if (ici != null)
            {
                img.Save(filename, ici, encoderParams);
            }
            else
            {
                img.Save(filename);
            }

            g.Dispose();
            img.Dispose();
            watermark.Dispose();
            imageAttributes.Dispose();
        }
コード例 #10
0
 /// <summary> Dispose of control </summary>
 public override void Dispose()
 {
     base.Dispose();
     drawnImageAttributesEnabled?.Dispose();
     drawnImageAttributesDisabled?.Dispose();
 }
コード例 #11
0
ファイル: PicHelper.cs プロジェクト: the404/xyz
        /// <summary>
        /// 在图片上生成图片水印
        /// </summary>
        /// <param name="sourcePath">原图片路径</param>
        /// <param name="targetPath">另存为路径</param>
        /// <param name="waterMarkFilePath">水印图片路径</param>
        /// <param name="positionType">图片水印位置:UL,UM , UR , ML , MM , MR , BL , BM , BR ,CUSTORM 为自定义.</param>
        /// <param name="quality">是否是高质量图片 取值范围0--100</param>
        /// <param name="watermarkTransparency">图片水印透明度 取值范围1--10 (10为不透明)</param>
        /// <returns></returns>
        public static bool PictureWatermark(string sourcePath, string targetPath, string waterMarkFilePath, PicWaterMarkPosition positionType, int quality, int watermarkTransparency)
        {
            System.Drawing.Image img = System.Drawing.Image.FromFile(sourcePath);
            System.Drawing.Bitmap outPut = new System.Drawing.Bitmap(img);
            try
            {
                #region using

                using (Graphics g = Graphics.FromImage(outPut))
                {
                    //设置高质量插值法
                    //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
                    //设置高质量,低速度呈现平滑程度
                    //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    System.Drawing.Image markImg = new System.Drawing.Bitmap(waterMarkFilePath);
                    if (markImg.Height >= img.Height || markImg.Width >= img.Width)
                    {
                        return false;
                    }
                    System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
                    System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap();
                    colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0);
                    colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0);
                    System.Drawing.Imaging.ColorMap[] remapTable = { colorMap };
                    imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap);
                    float transparency = 0.5F;
                    if (watermarkTransparency >= 1 && watermarkTransparency <= 10)
                    {
                        transparency = (watermarkTransparency / 10.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,  transparency, 0.0f},
                                                new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
                                            };

                    System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);
                    imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);
                    int xpos = 0;
                    int ypos = 0;

                    #region position

                    switch (positionType)
                    {
                        case PicWaterMarkPosition.UL:
                            xpos = (int)(img.Width * (float).01);
                            ypos = (int)(img.Height * (float).01);
                            break;

                        case PicWaterMarkPosition.UM:
                            xpos = (int)((img.Width * (float).50) - (markImg.Width / 2));
                            ypos = (int)(img.Height * (float).01);
                            break;

                        case PicWaterMarkPosition.UR:
                            xpos = (int)((img.Width * (float).99) - (markImg.Width));
                            ypos = (int)(img.Height * (float).01);
                            break;

                        case PicWaterMarkPosition.ML:
                            xpos = (int)(img.Width * (float).01);
                            ypos = (int)((img.Height * (float).50) - (markImg.Height / 2));
                            break;

                        case PicWaterMarkPosition.MM:
                            xpos = (int)((img.Width * (float).50) - (markImg.Width / 2));
                            ypos = (int)((img.Height * (float).50) - (markImg.Height / 2));
                            break;

                        case PicWaterMarkPosition.MR:
                            xpos = (int)((img.Width * (float).99) - (markImg.Width));
                            ypos = (int)((img.Height * (float).50) - (markImg.Height / 2));
                            break;

                        case PicWaterMarkPosition.BL:
                            xpos = (int)(img.Width * (float).01);
                            ypos = (int)((img.Height * (float).99) - markImg.Height);
                            break;

                        case PicWaterMarkPosition.BM:
                            xpos = (int)((img.Width * (float).50) - (markImg.Width / 2));
                            ypos = (int)((img.Height * (float).99) - markImg.Height);
                            break;

                        case PicWaterMarkPosition.BR:
                            xpos = (int)((img.Width * (float).99) - (markImg.Width));
                            ypos = (int)((img.Height * (float).99) - markImg.Height);
                            break;
                    }

                    #endregion position

                    g.DrawImage(markImg, new System.Drawing.Rectangle(xpos, ypos, markImg.Width, markImg.Height), 0, 0, markImg.Width, markImg.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes);
                    System.Drawing.Imaging.ImageCodecInfo[] codecs = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();
                    System.Drawing.Imaging.ImageCodecInfo ici = null;
                    foreach (System.Drawing.Imaging.ImageCodecInfo codec in codecs)
                    {
                        if (codec.MimeType.IndexOf("jpeg") > -1)
                        {
                            ici = codec;
                        }
                    }
                    System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters();
                    long[] qualityParam = new long[1];
                    if (quality < 0 || quality > 100)
                    {
                        quality = 80;
                    }
                    qualityParam[0] = quality;
                    System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam);
                    encoderParams.Param[0] = encoderParam;
                    if (ici != null)
                    {
                        outPut.Save(targetPath, ici, encoderParams);
                    }
                    else
                    {
                        outPut.Save(targetPath);
                    }
                    g.Dispose();
                    markImg.Dispose();
                    imageAttributes.Dispose();
                }

                #endregion using
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                if (outPut != null)
                {
                    outPut.Dispose();
                }
                if (img != null)
                {
                    img.Dispose();
                }
            }
            return true;
        }