C#(.net)水印图片的生成 - .net语言 -

C#(.net)水印图片的生成

时间:2010-01-27 14:36:01   来源:   评论:加载中...   点击:加载中...
/** * 使用说明:*  建议先定义一个WaterImage实例*  然后利用实例的属性,去匹配需要进行操作的参数*  然后定义一个WaterImageMan...

            ImageAttributes imageAttributes = new ImageAttributes();

            //
            //Colormap: 定义转换颜色的映射
            //
            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}, // red红色
           new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, //green绿色
           new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, //blue蓝色      
           new float[] {0.0f, 0.0f, 0.0f, alpha, 0.0f}, //透明度    
           new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}};//

            // ColorMatrix:定义包含 RGBA 空间坐标的 5 x 5 矩阵。
            // ImageAttributes 类的若干方法通过使用颜色矩阵调整图像颜色。
            ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);


            imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,
             ColorAdjustType.Bitmap);

            //
            //上面设置完颜色,下面开始设置位置
            //
            int xPosOfWm;
            int yPosOfWm;

            switch (position)
            {
                case ImagePosition.BottomMiddle:
                    xPosOfWm = (phWidth - wmWidth) / 2;
                    yPosOfWm = phHeight - wmHeight - 10;
                    break;



相关热词搜索:

 
上一篇:枚举 ENUM
下一篇:.net 中常用的26个优化
收藏 将此文推荐给朋友
分享到: