zoukankan      html  css  js  c++  java
  • .Net给图片添加水印效果

           /// <summary>
            ///  加水印图片
            /// </summary>
            /// <param name="picture">imge 对象</param>
            /// <param name="WaterMarkPicPath">水印图片的地址</param>
            public static void addWatermarkImage(Image _Image, string WaterMarkPicPath)
            {

                try
                {
                    Graphics picture = Graphics.FromImage(_Image);

                    Image watermark = new Bitmap(WaterMarkPicPath);
                    int _width = _Image.Width;
                    int _height = _Image.Height;

                    ImageAttributes imageAttributes = new ImageAttributes();
                    ColorMap colorMap = new ColorMap();

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

                    imageAttributes.SetRemapTable(remapTable, 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.1f, 0.0f},
                                                    new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
                                                };

                    ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);

                    imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                    //imageAttributes.SetColorKey(System.Drawing.Color.Black, System.Drawing.Color.Black, ColorAdjustType.Bitmap);

                    int xpos = 0;
                    int ypos = 0;
                    int WatermarkWidth = 0;
                    int WatermarkHeight = 0;
                    double bl = 1d;
                    WatermarkWidth = _width;
                    WatermarkHeight = _height;
                    xpos = 0;
                    ypos = 0;

                    picture.DrawImage(watermark, new Rectangle(xpos, ypos, WatermarkWidth, WatermarkHeight), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel, imageAttributes);
                    _Image = watermark;
                    watermark.Dispose();
                    imageAttributes.Dispose();
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("Exception in addWatermarkImage" + ex.Message);
                }
            }

  • 相关阅读:
    Struts2_模块包含
    Struts2_访问Web元素
    Struts2_简单数据验证
    获取当前日期
    iOS NSMutableArray添加NSInteger元素
    iOS label换行 自适应
    iOS高德地图自定义annotation添加不同图片
    @property(nonatomic) UIViewAutoresizing autoresizingMask;
    HTML
    图片压缩
  • 原文地址:https://www.cnblogs.com/huaku/p/3040207.html
Copyright © 2011-2022 走看看