在MFC中,CImageList类的SetOverlayImage方法可以使任意两个图像叠加成一个新的图像,或VB/VC的ImageList 控件中Overlay 方法具备同样功能,但我怎么也没找到C#中对应的方法,有谁知道,请告知,先谢过!!

解决方案 »

  1.   

    Bitmap vBitmapBack = new Bitmap(@"c:\temp\temp.bmp");
    Bitmap vBitmapFace = new Bitmap(@"c:\temp\1.bmp");
    Graphics vGraphics = Graphics.FromImage(vBitmapBack);
    vBitmapFace.MakeTransparent(Color.Fuchsia);
    vGraphics.DrawImage(vBitmapFace, new Point(10, 10));
    vBitmapBack.Save(@"c:\temp\2.bmp");//这样?
      

  2.   

    zswang(伴水清清)(专家门诊清洁工) ,谢谢了,我试试
      

  3.   

    zswang(伴水清清)(专家门诊清洁工) ,昨晚试了,不行,还有没有其他办法?
      

  4.   

    搂主,你所说的图像叠加是不是指把一张图片绘制到另一张图片上?
    Graphics.DrawImage()方法就可以了
    如果是半透明绘制还得用其他方法
    你先说清楚“叠加”是啥意思?
      

  5.   

    参考如下加半透明图片水印的方法,透明度可调     
            /// <summary>
            /// 加水印,对传入的Image对象操作
            /// </summary>
            /// <param name="waterFullPath">水印图片的完整路径</param>
            /// <param name="imgPhoto">要加水印的Bitmap对象,直接在上面加水印(ref 引用传递)</param>
            public static void AddWaterMark(string waterFullPath,ref Bitmap imgPhoto)
            {
                //string Copyright="Copyright ? 2005 - 2006 Lotour.com";            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);            //用水印BMP文件创建一个image对象 
                Image imgWater = new Bitmap(waterFullPath);
                int wmWidth = imgWater.Width;
                int wmHeight = imgWater.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 bmWater = new Bitmap(bmPhoto);
                bmWater.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
                //Load this Bitmap into a new Graphic Object
                Graphics grWater = Graphics.FromImage(bmWater);            //To achieve a transulcent water 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();            //水印被定义为一个100%的绿色背景l
                //这将是我们以transparency来查找并替换的颜色
                colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
                colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);             ColorMap[] remapTable = {colorMap};            imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);            //第二个颜色操作是用来改变水印的透明度
                //用包涵the coordinates for the RGBA space的一个5x5 的矩阵 
                //设置第三行第三列to 0.3f we achive a level of opacity
                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.8f,  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}}; 
                ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);            imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,
                ColorAdjustType.Bitmap);            //水印放在图像的右上角
                //向下10像素,向左10像素
                int xPosOfWm = ((phWidth - wmWidth)-10);
                int yPosOfWm = 10;            grWater.DrawImage(imgWater, 
                    new Rectangle(xPosOfWm,yPosOfWm,wmWidth,wmHeight),  //Set the detination Position
                    0,                  // 源图的横坐标位置
                    0,                  //  源图的纵坐标位置
                    wmWidth,            // 水印宽度
                    wmHeight,     // 水印高度
                    GraphicsUnit.Pixel, // Unit of measurment
                    imageAttributes);   //ImageAttributes Object            //以新图替换原始图
                imgPhoto = bmWater;
                grPhoto.Dispose();
                grWater.Dispose();
                imgWater.Dispose();
            }        /// <summary>
            /// 加水印(保存目标Stream)
            /// </summary>
            /// <param name="waterFullPath">水印图片的完整路径</param>
            /// <param name="imgPhoto">要加水印的Bitmap对象</param>
            /// <param name="destStream">加了水印的图片Stream</param>
            public static void AddWaterMark(string waterFullPath,ref Bitmap imgPhoto,Stream destStream)
            {
                //加水印
                AddWaterMark(waterFullPath,ref imgPhoto);            //保存加了水印的图片到Stream
                imgPhoto.Save(destStream, ImageFormat.Jpeg);
            }        /// <summary>
            /// 加水印(直接保存目标文件)
            /// </summary>
            /// <param name="waterFullPath">水印图片的完整路径</param>
            /// <param name="imgPhoto">要加水印的Bitmap对象</param>
            /// <param name="destFile">加了水印的图片保存路径</param>
            public static void AddWaterMark(string waterFullPath,ref Bitmap imgPhoto,string destFile)
            {
                //加水印
                AddWaterMark(waterFullPath,ref imgPhoto);            //保存加了水印的图片
                imgPhoto.Save(destFile, ImageFormat.Jpeg);
            }
      

  6.   

    谢谢各位,我的叠加意思:两个图像叠加成一个新的图像,原来的两个图像保持不变!
    viena(维也纳nn) ( ) 提供的办法,我马上试试
      

  7.   

    怎么样个叠加法?大家半透明叠加还是变成一个image两张图片层?