在MFC中,CImageList类的SetOverlayImage方法可以使任意两个图像叠加成一个新的图像,或VB/VC的ImageList 控件中Overlay 方法具备同样功能,但我怎么也没找到C#中对应的方法,有谁知道,请告知,先谢过!!
解决方案 »
- 一卡通,不同系统融合问题
- 大家帮忙看看这个ArrayList问题。(三个foreach中的输出语句为什么不输出)
- 求C#解决方法求:用C#,将查询到的一个表,导出到excel打印的方法,说明要引用哪些命名空间,要导入什么文件,最好有个实例
- GridView的页码显示位置问题
- WinForm背景图片问题
- C#水晶报表高手请进.怎么把GRIDVIEW里的数据放到水晶报表里..
- XP下不能安装SQL SERVER 2000 企业版,怎么搞,我只有这个软件,怎么解决,大侠们出出主意啊!!!
- visual c#怎么连接SQL SEVER??
- 谁知道 DataGrid 能否做不规则表格???
- 请大家推荐几本c#数据库编程方面的书?
- 关于网络游戏中的问题?
- 求教:關於Timers在C#.NET的WEB開發中應該怎樣應用
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");//这样?
Graphics.DrawImage()方法就可以了
如果是半透明绘制还得用其他方法
你先说清楚“叠加”是啥意思?
/// <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);
}
viena(维也纳nn) ( ) 提供的办法,我马上试试