为freetextbox1.6.5上传图片加上水印
Graphics的DrawImage方法,定义了多种原型,可以在制定位置绘制指定Image对象。利用此方法可以在图片对象上再绘制一个水印图片。结合FreeTextBox方便的图片上传功能,可以实现一个适合图片新闻较多的新闻系统。以下WaterMark方法所带参数为文件流,原始图片名称,水印图片名称,图片保存路径等,对应注释理解代码应该没有多大问题。
-----------------------------------------------------------------
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方法放到代码中。
转载于:https://www.cnblogs.com/yssoft/archive/2009/05/03/1448248.html
为freetextbox1.6.5上传图片加上水印相关推荐
- Asp.net(C#)给图片加上水印效果(转自园上的Seven Eleven)
Asp.net(C#)给图片加上水印效果 private void Btn_Upload_Click(object sender, System.EventArgs e) { ...
- python的控件text的文本属性_只需6行Python代码就给图片加上水印——你一看就会了...
大家在做项目开发的过程中,会不会经常遇到需要处理图片却没有快速有效的工具的情况呢?比如客户需要给图片加上水印,你可能会用到PS这些高级软件去处理,这样虽然有效果但是需要相对较长的时间:作为程序猿,你一 ...
- java ueditor 图片上传加水印_Ueditor编辑器上传图片加水印【亲测可用】-帝国CMS整合...
Ueditor编辑器上传图片加水印 百度一下,有很多,但是方法都是一样的,写的不清不楚的.对于代码不是很了解的我们,却是头大.我整理了一下,下载下面的压缩包,解压缩之后,直接上传到 ueditor ...
- html自动给图片加上水印 代码_如何给一千张图片去水印?还好我会python,100行代码轻松搞定...
写在前面 近期好多网友私信我,问我编程该怎么学习.怎么入门.我觉得编程学习,就像写文章一样,需要积累. 如果把代码每个字符拆开,大伙都认识,但是组合在一起,就是另外一回事了.所以我的建议是,学习编程, ...
- python将excel转换成图片_python-尝试将Excel文件保存为图片并加上水印
python-尝试将Excel文件保存为图片并加上水印 场景:并不是将 excel 的 chart 生成图片,而是将整个表格内容生成图片. 1. 准备工作 目前搜索不到已有的方法,只能自己尝试写一个, ...
- python将excel转换成图片_python-尝试将Excel文件保存为图片并加上水印-阿里云开发者社区...
python-尝试将Excel文件保存为图片并加上水印 场景:并不是将 excel 的 chart 生成图片,而是将整个表格内容生成图片. 1. 准备工作 目前搜索不到已有的方法,只能自己尝试写一个, ...
- Android视频编辑器(二)预览、录制视频加上水印和美白磨皮效果
前言 这是视频编辑器系列的第二篇文章,在上篇文章中,我们讲解了利用OpenGl和SurfaceView进行视频预览,MediaCodec和MeidaMuxer进行视频录制和断点续录.而这篇主 ...
- phpcms富文本框上传图片去除水印
客户说上传图片有水印.通过以下方法去除: 1.把statics/images/water文件删除. 2.在phpcms/libs/classes/image.class.php中做以下操作即可去除水印 ...
- phpcms上传图片去除水印
客户说上传图片有水印.通过以下方法去除: 1.把statics/images/water文件删除. 2.在phpcms/libs/classes/image.class.php中做以下操作即可去除水印 ...
最新文章
- thinkPHP 模板的使用技巧(十三)
- linux下vi命令大全[转]
- .net数据控件的冒泡事件
- Java全套零基础视频教程,2019最新编程
- 第三次学JAVA再学不好就吃翔(part61)--基本数据类型包装类
- couchbase_Couchbase 2.0归类视图简介
- 【工作经验分享】java图片转文字
- TensorFlow2.0(十二)--实现简单RNN与LSTM网络
- mysql启动错误处理
- 大数据-概念-应用-弊端
- 51Nod-1010 只包含因子2 3 5的数【打表+排序+二分搜索】
- EasyUI Tree添加节点
- 中职计算机ps公开课教案,全国“xx杯”计算机类说课大赛课件一等奖作品:《利用PS蒙版制作照片的蒙太奇效果》教学设计.doc...
- ps4如何无线连接网络连接服务器,PC党最佳选择!达人发布PS4手柄无线连接PC教程...
- mysql三表联合查询_求三表联合查询的SQL查询语句
- Sony IPELA E系列网络摄像头远程命令执行漏洞警告
- Docker端口映射不起作用的解决办法
- c语言太极图编程语言,C语言画图之 画个太极图
- 2022-2028年中国网络直播行业商业模式创新与投资机会深度研究报告
- Why it occurs this error [The JSON value could not be converted to System.Nullable]