给图片打水印问题 提供一个图片的地址,然后你把这个图片打上水印。要求:可以自己设置水印的透明度,以及水印的位置。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 MakeThumbnail(xx, xx, 100, 100, "Cut"); // 生成缩略图方法 http://www.svnhost.cn/Article/?k=%E5%9B%BE /// <summary> /// 生成水印,源代码来自网上,修改了几个bug /// </summary> /// <param name="sourceFile">底图</param> /// <param name="waterMarkFile">水印图</param> /// <param name="saveFile">要保存的文件</param> /// <param name="local">位置:左上(1)、左下(2)、右上(3)、右下(4)、居中(5)</param> /// <param name="alpha">透明度(1-100)</param> public void DrawImages(string sourceFile, string saveFile, int local, int alpha) { //原图 System.Drawing.Image m_image = System.Drawing.Image.FromFile(sourceFile); Bitmap sImage = new Bitmap(m_image); m_image.Dispose(); int sWidth = sImage.Width; int sHeight = sImage.Height; //水印图 string m_locallogo; if (sWidth > 200 && sHeight > 50) { m_locallogo = Server.MapPath("/upload_picture/img_logo.gif"); } else { m_locallogo = Server.MapPath("/upload_picture/img_logo_small.gif"); } Bitmap wImage = new Bitmap(m_locallogo); int wWidth = wImage.Width; int wHeight = wImage.Height; //make Graphics. Graphics g = Graphics.FromImage(sImage); int x; //临时变量 int y; //监时变量 int x1 = 0; //原图和水印图的宽度差,即开始绘图的X位置 int y1 = 0; //原图和水印图的高度差,即开始绘图的Y位置 int w = 0; //生成的水印图的宽度,即结束绘图的X位置 int h = 0; //生成的水印图的高度,即结束绘图的Y位置 int al; //alpha int rl; //Red int gl; //Green int bl; //Blue //校验透明度 al = alpha; if (sWidth > wWidth && sHeight > wHeight) //如果源图比水印图大 { switch (local) { case 1: //左上 x1 = 0; y1 = 0; break; case 2: //左下 x1 = 0; if ((sHeight - wHeight) > 0) //源图比水印图高 y1 = sHeight - wHeight; else y1 = sWidth; break; case 3: //右上 y1 = 0; if ((sWidth - wWidth) > 0) // 源图比水印图宽 x1 = sWidth - wWidth; else x1 = sWidth; break; case 4: //右下 //计算高度 if ((sHeight - wHeight) > 0) //源图比水印图高 y1 = sHeight - wHeight; else y1 = sWidth; //计算宽度 if ((sWidth - wWidth) > 0) // 源图比水印图宽 x1 = sWidth - wWidth; else x1 = sWidth; break; case 5: //居中 //计算高度 if ((sHeight - wHeight) > 0) //源图比水印图高 y1 = (sHeight - wHeight) / 2; else y1 = sWidth; //计算宽度 if ((sWidth - wWidth) > 0) // 源图比水印图宽 x1 = (sWidth - wWidth) / 2; else x1 = sWidth; break; } if ((sHeight - wHeight) > 0) h = wHeight; else h = sHeight; if ((sWidth - wWidth) > 0) w = wWidth; else w = sWidth; } else //源图比水印图小 { x1 = 0; y1 = 0; w = sWidth; h = sHeight; } //开始绘图 for (x = 1; x < w; x++) { for (y = 1; y < h; y++) { try { rl = wImage.GetPixel(x, y).R; gl = wImage.GetPixel(x, y).G; bl = wImage.GetPixel(x, y).B; } catch { continue; } if (!(rl == 255 && gl == 255 && bl == 255)) { if (rl + 25 < 255) rl += 25; if (gl + 25 < 255) gl += 25; if (bl + 25 < 255) bl += 25; g.DrawEllipse(new Pen(new SolidBrush(Color.FromArgb(al, rl, gl, bl))), x1 + x, y1 + y, 1, 1); } else { g.DrawEllipse(new Pen(new SolidBrush(Color.FromArgb(0, rl, gl, bl))), x1 + x, y1 + y, 1, 1); } } } g.Save(); g.Dispose(); wImage.Dispose(); sImage.Save(saveFile); sImage.Dispose(); } http://www.svnhost.cn/Article/Detail-14.shtml这片文章好像少2个类啊 用GDI+贴图上去就是了,很简单的,买本专门讲GDI+的书看看吧。 看一下Handler,两种方式,一种需要修改所有图片的路径,一种需要在WebConfig中配置一下即可 一个小问题关于弹出提示窗口的 【求助,急急急】正则取值问题。 网站更新问题谢谢 (世道凄凉啊!~~)问下FCK这个插件拉进去后有多大? the status code returned from the server was:12031是什么错误? 根据数据库条件,使用ajax判断文本框内容是否符合条件 XMLHTTP 乱码问题 100分 请问:如何时子控件随则主控件改变大小(WebCustomControl) 如何让IIS在应用程序池启动的同时启动一个自定的线程 關於TreeView的小問題 web服务器连接oracle数据库需要安装什么 存储过程使用出错(急)
/// 生成水印,源代码来自网上,修改了几个bug
/// </summary>
/// <param name="sourceFile">底图</param>
/// <param name="waterMarkFile">水印图</param>
/// <param name="saveFile">要保存的文件</param>
/// <param name="local">位置:左上(1)、左下(2)、右上(3)、右下(4)、居中(5)</param>
/// <param name="alpha">透明度(1-100)</param>
public void DrawImages(string sourceFile, string saveFile, int local, int alpha)
{
//原图
System.Drawing.Image m_image = System.Drawing.Image.FromFile(sourceFile);
Bitmap sImage = new Bitmap(m_image);
m_image.Dispose();
int sWidth = sImage.Width;
int sHeight = sImage.Height; //水印图
string m_locallogo;
if (sWidth > 200 && sHeight > 50)
{
m_locallogo = Server.MapPath("/upload_picture/img_logo.gif");
}
else
{
m_locallogo = Server.MapPath("/upload_picture/img_logo_small.gif");
} Bitmap wImage = new Bitmap(m_locallogo);
int wWidth = wImage.Width;
int wHeight = wImage.Height; //make Graphics.
Graphics g = Graphics.FromImage(sImage);
int x; //临时变量
int y; //监时变量
int x1 = 0; //原图和水印图的宽度差,即开始绘图的X位置
int y1 = 0; //原图和水印图的高度差,即开始绘图的Y位置
int w = 0; //生成的水印图的宽度,即结束绘图的X位置
int h = 0; //生成的水印图的高度,即结束绘图的Y位置
int al; //alpha
int rl; //Red
int gl; //Green
int bl; //Blue //校验透明度
al = alpha; if (sWidth > wWidth && sHeight > wHeight) //如果源图比水印图大
{
switch (local)
{
case 1: //左上
x1 = 0;
y1 = 0;
break;
case 2: //左下
x1 = 0;
if ((sHeight - wHeight) > 0) //源图比水印图高
y1 = sHeight - wHeight;
else
y1 = sWidth;
break;
case 3: //右上
y1 = 0;
if ((sWidth - wWidth) > 0) // 源图比水印图宽
x1 = sWidth - wWidth;
else
x1 = sWidth;
break;
case 4: //右下
//计算高度
if ((sHeight - wHeight) > 0) //源图比水印图高
y1 = sHeight - wHeight;
else
y1 = sWidth;
//计算宽度
if ((sWidth - wWidth) > 0) // 源图比水印图宽
x1 = sWidth - wWidth;
else
x1 = sWidth;
break;
case 5: //居中
//计算高度
if ((sHeight - wHeight) > 0) //源图比水印图高
y1 = (sHeight - wHeight) / 2;
else
y1 = sWidth;
//计算宽度
if ((sWidth - wWidth) > 0) // 源图比水印图宽
x1 = (sWidth - wWidth) / 2;
else
x1 = sWidth;
break;
}
if ((sHeight - wHeight) > 0)
h = wHeight;
else
h = sHeight;
if ((sWidth - wWidth) > 0)
w = wWidth;
else
w = sWidth;
}
else //源图比水印图小
{
x1 = 0;
y1 = 0;
w = sWidth;
h = sHeight;
} //开始绘图
for (x = 1; x < w; x++)
{
for (y = 1; y < h; y++)
{
try
{
rl = wImage.GetPixel(x, y).R;
gl = wImage.GetPixel(x, y).G;
bl = wImage.GetPixel(x, y).B;
}
catch
{
continue;
} if (!(rl == 255 && gl == 255 && bl == 255))
{
if (rl + 25 < 255)
rl += 25;
if (gl + 25 < 255)
gl += 25;
if (bl + 25 < 255)
bl += 25; g.DrawEllipse(new Pen(new SolidBrush(Color.FromArgb(al, rl, gl, bl))), x1 + x, y1 + y, 1, 1);
}
else
{
g.DrawEllipse(new Pen(new SolidBrush(Color.FromArgb(0, rl, gl, bl))), x1 + x, y1 + y, 1, 1);
}
}
}
g.Save();
g.Dispose();
wImage.Dispose(); sImage.Save(saveFile);
sImage.Dispose();
}