- 热门文章:
- · 自定义配置节处理实现个性化web.config
- · 使用xmlhttp为网站增加股市行情查询功能
- · .Net Enterprise服务器可能太早冠上.Net名号了
- · 维护ASP的会话状态
- · 浅谈引用计数
- · 使你的窗体保留在桌面的最上面
- · 研究心得------->Seskin控件包中SeskinEdit汉字问题的解决办法
- · 建立三层结构的ASP应用程序
- · 研究心得------->CPU信息的获得,比较全面的
- · Sender 的??用:所有Edit共用一???^?V格式
- · override deal with window closing in database application
- · C++ 和 Delphi 的函数覆盖(Override)与重载(overload
上一篇:asp论坛在线人数统计研究 >>
为freetextbox1.6.5上传图片加上水印
-----------------------------------------------------------------
public void WaterMark(Stream inputStream, string fileName, string
markName, string picPath)
{
string WorkingDirectory =
HttpContext.Current.Request.PhysicalApplicationPath + "\\" + picPath;
Stream PhotoStream = inputStream;
string WatermarkName = markName;
string PhotoFinalName = fileName;
//create a image object containing the photograph to watermark
System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(PhotoStream);
int phWidth = imgPhoto.Width;
int phHeight = imgPhoto.Height;
//create a image object containing the watermark
System.Drawing.Image imgWatermark = new Bitmap(WorkingDirectory + "\\" + WatermarkName);
int wmWidth = imgWatermark.Width;
int wmHeight = imgWatermark.Height;
//Create a Bitmap
Bitmap bmWatermark = new Bitmap(PhotoStream);
bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
//Load this Bitmap into a new Graphic Object
Graphics grWatermark = Graphics.FromImage(bmWatermark);
ImageAttributes imageAttributes = new ImageAttributes();
//This color manipulation is used to change the opacity of the
//watermark. This is done by applying a 5x5 matrix that contains the
//coordinates for the RGBA space. By setting the 3rd row and 3rd column
//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.0f, 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);
//For this example we will place the watermark in the upper right
//hand corner of the photograph. offset down 10 pixels and to the
//left 10 pixles
int xPosOfWm = ((phWidth - wmWidth)-10);
int yPosOfWm = 10;
grWatermark.DrawImage(imgWatermark,
new Rectangle(xPosOfWm,yPosOfWm,wmWidth,wmHeight), //Set the detination Position
0, // x-coordinate of the portion of the source image to draw.
0, // y-coordinate of the portion of the source image to draw.
wmWidth, // Watermark Width
wmHeight, // Watermark Height
GraphicsUnit.Pixel, // Unit of measurment
imageAttributes); //ImageAttributes Object
//Replace the original photgraphs bitmap with the new Bitmap
imgPhoto = bmWatermark;
grWatermark.Dispose();
//save new image to file system.
imgPhoto.Save(WorkingDirectory + "\\" + PhotoFinalName, ImageFormat.Jpeg);
imgPhoto.Dispose();
imgWatermark.Dispose();
PhotoStream.Close();
}
--------------------------------------------------------------------
FTB的图片上传主要利用HtmlInputFile控件,对应HtmlInputFile类的属性PostedFile,它含有SaveAs方法可以来保存图片。当然我们不希望在图片保存完之后再专门读它建Graphics对象来再次处理,因此查了MSDN,发现PostedFile属性返回的是HttpPostedFile 类的一个实例,而HttpPostedFile 有InputStream对象,通过HtmlInputFile控件上传的文件可以通过该Stream对象获得上传文件流,作为WaterMake的参数实现最终功能。
所以最后只要在FTB中把ftb.imagegallery.aspx文件第77行UploadFile.PostedFile.SaveAs那句注释,并替换为对WaterMake方法的调用就行:WaterMark(UploadFile.PostedFile.InputStream, UploadFileName, "watermark.bmp", "UploadPics");当然还要把WaterMake方法放到代码中。
下一篇:自定义配置节处理实现个性化web.config >>
相关文章:
- · 正确处理ASP动态网页中的容错机制
- · 几例在ASP存储过程的使用方法
- · 实现让每句话的头一个字母都大写
- · 如何尽快释放掉Connection对象建立的连接?
- · Connection对象的应用
- · 利用ASP打造网站论坛DIY
- · Asp中代码与页面的分离
- · 一个ASP版的图片浏览管理器
- · 实现有管理功能的ASP留言板
- · 编译asp应用程序成为exe文件
- · 如何准确定时运行ASP文件
- · ASP整合的一个SQL语句类
- · Jmail发信的实例,模块化随时调用
- · ASP字数计算函数
- · 无刷新随时取得用户当前活动信息
- · ASP自定义函数,仿VBA中域函数DLookup
- · asp中对ip进行过滤限制函数
- · 让ASP程序运行于非Windows平台
- · ASP中实现文件上传方法的研究
- · asp国标转大五码
- · Global.asa文件用法大全
- · 微软建议的ASP性能优化28条守则
- · 在ASP中取得服务器网卡的MAC地址、DNS地址等网络信息
- · ASP中记录的分页
- · 下载网页中的所有资源
- · 函数方便制作管理界面
- · 无限级目录树+记忆节点状态
- · 利用C#在SQL Server2000存取图像 For Window
- · 通过MSXML2自动获取QQ个人头像及在线情况(给初学者)
- · ASP模板类[实现一维循环和二维循环,可以从文件、数据库、变量取摸板]
- · 各种存储过程使用指南
- · 树型结构在ASP中的简单解决
- · 用ASPJPEG组件制作图片的缩略图和加水印
- · 用asp制作强大的搜索引擎(一)
- · VBscript和javascript的选择
- · 在ASP中使用SQL语句之2:用WHERE子句设置查询条件
- · 在线压缩WINRAR文件
- · 在线解压缩上传的WINRAR文件
