.net上传图片加水印的问题

chenqi747 2009-05-08 07:35:36
怎么在网站的上传功能里加上附加水印的功能啊?那个位大哥帮帮忙啊啊啊啊啊啊啊
...全文
1086 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
you97 2012-02-07
  • 打赏
  • 举报
回复
wwcom606 2010-04-17
  • 打赏
  • 举报
回复
我顶!!很好,刚刚学会处理水印相片的效果!!
huangwenquan123 2010-04-17
  • 打赏
  • 举报
回复
好贴!
fwacky 2010-01-12
  • 打赏
  • 举报
回复
好贴!
惜分飞 2009-05-09
  • 打赏
  • 举报
回复
要的话,可以联系我
邮箱8chf@163.com,我刚刚做过这个东西的,代码太长
a2220046 2009-05-09
  • 打赏
  • 举报
回复
帮顶一下
cat_hsfz 2009-05-09
  • 打赏
  • 举报
回复
用GDI+画上去,找本GDI+的书看看吧,照抄代码不一定适合你。
  • 打赏
  • 举报
回复
up
银狐被占用 2009-05-09
  • 打赏
  • 举报
回复
来顶牛人的。。。
lijie9693 2009-05-09
  • 打赏
  • 举报
回复
up..
龙宜坡 2009-05-09
  • 打赏
  • 举报
回复
这方面的资料很多!
wndsc 2009-05-09
  • 打赏
  • 举报
回复
为什么我添加的 时候 总提示内存不足??
sxmonsy 2009-05-09
  • 打赏
  • 举报
回复
友情UP吧。。。。
tianzhen1022 2009-05-09
  • 打赏
  • 举报
回复
我来看看
gang027 2009-05-09
  • 打赏
  • 举报
回复
up
Study_Work_2009 2009-05-09
  • 打赏
  • 举报
回复
顶一下
teerhu 2009-05-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jingshuaizh 的回复:]
C# code
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileContentType = FileUpload1.PostedFile.ContentType;
if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg")
{
string name = FileUpload1.P…
[/Quote]
帮顶
wuyq11 2009-05-08
  • 打赏
  • 举报
回复
public class picmark
{
private string modifyImagePath = null;
private string drawedImagePath = null;
private int rightSpace;
private int bottoamSpace;
private int lucencyPercent = 70;
private string outPath = null;
public picmark()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public string ModifyImagePath
{
get { return this.modifyImagePath; }
set { this.modifyImagePath = value; }
}
public string DrawedImagePath
{
get { return this.drawedImagePath; }
set { this.drawedImagePath = value; }
}

public int RightSpace
{
get { return this.rightSpace; }
set { this.rightSpace = value; }
}
public int BottoamSpace
{
get { return this.bottoamSpace; }
set { this.bottoamSpace = value; }
}
public int LucencyPercent
{
get { return this.lucencyPercent; }
set
{
if (value >= 0 && value <= 100)
this.lucencyPercent = value;
}
}

public string OutPath
{
get { return this.outPath; }
set { this.outPath = value; }
}

public void DrawImage()
{
Image modifyImage = null;
Image drawedImage = null;
Graphics g = null;
try
{
modifyImage = Image.FromFile(this.ModifyImagePath);
drawedImage = Image.FromFile(this.DrawedImagePath);
g = Graphics.FromImage(modifyImage);
int x = modifyImage.Width - this.rightSpace;
int y = modifyImage.Height - this.BottoamSpace;
float[][] matrixItems ={
new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, (float)this.LucencyPercent/100f, 0},
new float[] {0, 0, 0, 0, 1}};
ColorMatrix colorMatrix = new ColorMatrix(matrixItems);
ImageAttributes imgAttr = new ImageAttributes();
imgAttr.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.DrawImage(
drawedImage,
new Rectangle(x, y, drawedImage.Width, drawedImage.Height),
0, 0, drawedImage.Width, drawedImage.Height,
GraphicsUnit.Pixel, imgAttr);
string[] allowImageType ={ ".jpg", ".gif", ".png", ".bmp", ".tiff", ".wmf", ".ico" };
FileInfo file = new FileInfo(this.ModifyImagePath);
ImageFormat imageType = ImageFormat.Gif;
switch (file.Extension.ToLower())
{
case ".jpg":
imageType = ImageFormat.Jpeg;
break;
case ".gif":
imageType = ImageFormat.Gif;
break;
case ".png":
imageType = ImageFormat.Png;
break;
case ".bmp":
imageType = ImageFormat.Bmp;
break;
case ".tif":
imageType = ImageFormat.Tiff;
break;
case ".wmf":
imageType = ImageFormat.Wmf;
break;
case ".ico":
imageType = ImageFormat.Icon;
break;
default:
break;
}
MemoryStream ms = new MemoryStream();
modifyImage.Save(ms, imageType);
byte[] imgData = ms.ToArray();
modifyImage.Dispose();
drawedImage.Dispose();
g.Dispose();
FileStream fs = null;
if (this.OutPath == null || this.OutPath == "")
{
File.Delete(this.ModifyImagePath);
fs = new FileStream(this.ModifyImagePath, FileMode.Create, FileAccess.Write);
}
else
{
fs = new FileStream(this.OutPath, FileMode.Create, FileAccess.Write);
}
if (fs != null)
{
fs.Write(imgData, 0, imgData.Length);
fs.Close();
}
}
finally
{
try
{
drawedImage.Dispose();
modifyImage.Dispose();
g.Dispose();
}
catch { ;}
}
}
}
指间、魔法师 2009-05-08
  • 打赏
  • 举报
回复
我先保存 嘿嘿
only_lonely 2009-05-08
  • 打赏
  • 举报
回复
我汗,牛人牛码!
加载更多回复(5)

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧