首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

制作水印图片叠加到原图后两图跌加处出现白点有关问题?(急)

2012-03-05 
制作水印图片叠加到原图后两图跌加处出现白点问题?(急)运行都成功的,但是在跌加好的图片上,原图和跌加上去

制作水印图片叠加到原图后两图跌加处出现白点问题?(急)
运行都成功的,但是在跌加好的图片上,原图和跌加上去的图片交合处会出现白色斑点,高手帮帮我啊!
源码如下:
int   phWidth   =   imgPhoto.Width;
                        int   phHeight   =   imgPhoto.Height;

                        //创建一个与原图尺寸相同的位图
                        Bitmap   bmPhoto   =   new   Bitmap(phWidth,   phHeight,   PixelFormat.Format24bppRgb);
                        bmPhoto.SetResolution(imgPhoto.HorizontalResolution,   imgPhoto.VerticalResolution);

                        //位图装载到一个Graphics对象
                        Graphics   grPhoto   =   Graphics.FromImage(bmPhoto);
                        //grPhoto.

                        //用水印BMP文件创建一个image对象  
                        System.Drawing.Image   imgWatermark   =   imgTezh;
                        int   wmWidth   =   imgWatermark.Width;
                        int   wmHeight   =   imgWatermark.Height;

                        //设置图片质量
                        grPhoto.SmoothingMode   =   SmoothingMode.AntiAlias;

                        //以原始尺寸把照片图像画到此graphics对象
                        grPhoto.DrawImage(
                        imgPhoto,   //   Photo   Image   object
                        new   Rectangle(0,   0,   phWidth,   phHeight),   //   Rectangle   structure
                        0,   //   x-coordinate   of   the   portion   of   the   source   image   to   draw.  
                        0,   //   y-coordinate   of   the   portion   of   the   source   image   to   draw.  
                        phWidth,   //   Width   of   the   portion   of   the   source   image   to   draw.  
                        phHeight,   //   Height   of   the   portion   of   the   source   image   to   draw.  
                        GraphicsUnit.Pixel);   //   Units   of   measure  

                        //基于前面已修改的Bitmap创建一个新Bitmap  


                        Bitmap   bmWatermark   =   new   Bitmap(bmPhoto);
                        bmWatermark.SetResolution(imgPhoto.HorizontalResolution,   imgPhoto.VerticalResolution);
                        //Load   this   Bitmap   into   a   new   Graphic   Object
                        Graphics   grWatermark   =   Graphics.FromImage(bmWatermark);

                        //To   achieve   a   transulcent   watermark   we   will   apply   (2)   color  
                        //manipulations   by   defineing   a   ImageAttributes   object   and  
                        //seting   (2)   of   its   properties.
                        ImageAttributes   imageAttributes   =   new   ImageAttributes();

                        //第一步是以透明色(Alpha=0,   R=0,   G=0,   B=0)来替换背景色  
                        //为此我们将使用一个Colormap并用它来定义一个RemapTable
                        ColorMap   colorMap   =   new   ColorMap();
                        ColorMap   colorMap2   =   new   ColorMap();

                        //水印被定义为一个100%的绿色背景l
                        //这将是我们以transparency来查找并替换的颜色
                        colorMap.OldColor   =   Color.FromArgb(255,   255,   255,   255);
                        colorMap.NewColor   =   Color.FromArgb(0,255,255,   255);
                        colorMap2.OldColor   =   Color.FromArgb(255,   0,   0,   0);
                        colorMap2.NewColor   =   Color.FromArgb(255,   0,   0,   255);

                        ColorMap[]   remapTable   =   {   colorMap,   colorMap2   };

                        imageAttributes.SetRemapTable(remapTable,   ColorAdjustType.Bitmap);

                        int   xPosOfWm   =   0;
                        int   yPosOfWm   =   0;

                        grWatermark.DrawImage(imgWatermark,
                        new   Rectangle(xPosOfWm,   yPosOfWm,   wmWidth,   wmHeight),   //Set   the   detination   Position


                        0,   //   源图的横坐标位置
                        0,   //   源图的纵坐标位置
                        wmWidth,   //   水印宽度
                        wmHeight,   //   水印高度
                        GraphicsUnit.Pixel,   //   Unit   of   measurment
                        imageAttributes);   //ImageAttributes   Object

                        //以新图替换原始图
                        imgPhoto   =   bmWatermark;
                        grPhoto.Dispose();
                        grWatermark.Dispose();

[解决办法]
看看这个添加水印的
/// <summary>
/// 在图片上生成图片水印
/// </summary>
/// <param name= "Path "> 原服务器图片路径 </param>
/// <param name= "Path_syp "> 生成图片路径 </param>
/// <param name= "Path_sypf "> 水印图片路径 </param>
private void AddPicturt(string Path,string Path_syp,string Path_sypf)
{
System.Drawing.Image image=System.Drawing.Image.FromFile(Path);
System.Drawing.Image copyImage=System.Drawing.Image.FromFile(Path_sypf);
System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(image);

g.DrawImage(copyImage,new System.Drawing.Rectangle(image.Width-copyImage.Width,image.Height-copyImage.Height,copyImage.Width,copyImage.Height),0,0,copyImage.Width,copyImage.Height,System.Drawing.GraphicsUnit.Pixel);

image.Save(Path_syp);
image.Dispose();
}

热点排行