在图像上加水印 [英] watermarking on images

查看:92
本文介绍了在图像上加水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想开发一个在线应用程序,用户可以在图像上输入任何单词(fname,lname)本身.
并且该图像可以从他/她的计算机上下载.

例如
就像在线表格申请一样.
用户自行填写在线表格,然后下载该表格.


但是,我要在图像上填写表格.


谢谢,

Hello,

I want to develop one online application, which user enter any word (fname,lname) itself on images.
and also that image can be download his/her computers.

e.g
Like online form application.
user fill up online form it self and then his/her download that form.


But,I want fill up the form on image.


Thanks,

推荐答案

请点击链接以找到解决方案.希望它们会为您提供帮助.

http://www.daniweb.com/web-development/aspnet/线程/105229/add-watermark-in-image [ ^ ]

在ASP.NET中打印页面上的水印图像 [ ^ ]

谢谢
Please following the links to find the solution.May they will help you.

http://www.daniweb.com/web-development/aspnet/threads/105229/add-watermark-in-image[^]

Watermark image on page print in ASP.NET[^]

Thanks


两种有效的方法..您可以创建一个除水印之外都是透明的gif文件,并创建与默认图像相同或近似的大小.然后在页面上,将div的背景设置为默认图像,并将div的大小设置为默认图像的大小.然后在div内,放置水印的.这使大多数人无法复制和保存您的图片.

另一种方法是在运行时动态完成.这会在服务器上浪费大量的资源,并且只要调用任何映像,就总是如此.我建议远离它.

我的操作方式是通过网站将图片上传到服务器,保存图片的温度,打开图片的温度,调整大小,然后在其中添加水印(此刻只是文本),然后将其保存到所需的名称和目录.我对缩略图和主图像都这样做.我会为您提供一个可能需要使用的调整大小功能和一个水印功能.

您需要以下名称空间:

two effective ways to do this.. You can create a gif file that is transparent except for your watermark and create it the same size, or close to, of the default image. Then on your page, set the background of a div to the default image, and the size of the div to the size of the default image. Then inside the div, place the of the watermark. This stops most people from copying and saving your pictures.

Anther way is to have it done dynamically at runtime. This creates a krap load of resources on your server and will always as long as any image is called. I would recommend staying away from it.

The way that I do it is that I upload the picture to my server through a website, save a temp of it, open the temp, resize and then add a watermark to it (just text at the moment).. then save it to the name and directory wanted. I do this both for thumbnails and main images. I''ll give you a resize function and a watermark function that you might want to use.

You need these namespaces:

<![CDATA[<%@ import Namespace="System.IO" %>
<![CDATA[<%@ import Namespace="System.Drawing.Imaging" %>
<![CDATA[<%@ import Namespace="System.Drawing" %>
<![CDATA[<%@ import Namespace="System.Drawing.Drawing2D" %>
resize function:

Function generateThumbnail(ByVal newWidth As Integer, ByVal strFileName As String, ByVal newStrFileName As String)
  Dim bmp As Bitmap
  Dim newHeight As Integer
  Dim resized As Bitmap
  Dim FilePath As String = Server.MapPath("/images/")
  bmp = System.Drawing.Image.FromFile(FilePath & strFileName & ".jpg")
  newHeight = (newWidth/bmp.width)*bmp.Height
  resized = new Bitmap(newWidth,newHeight)
  newStrFileName = FilePath & newStrFileName & ".jpg"
  
  Dim g as Graphics = Graphics.FromImage(resized)
  g.SmoothingMode = SmoothingMode.HighQuality
  g.CompositingQuality = CompositingQuality.HighQuality
  g.InterpolationMode = InterpolationMode.High
  g.DrawImage(bmp, new Rectangle(0,0,resized.Width,resized.Height),0,0,bmp.Width,bmp.Height,GraphicsUnit.Pixel)
  g.Dispose()
  resized.Save(newStrFileName,ImageFormat.Jpeg)
  bmp.dispose()
End Function
watermark function:

Function watermark(ByVal strFileName As String, ByVal newStrFileName As String)
  Dim FilePath As String = Server.MapPath("/images/")
  Dim bmp As Bitmap = System.Drawing.Image.FromFile(FilePath & strFileName & ".jpg")
  Dim strWatermark As String = "WATERMARK TEXT"
  Dim canvas As Graphics = Graphics.FromImage(resized)
  Dim StringSizeF As SizeF, DesiredWidth As Single, wmFont As Font, RequiredFontSize As Single, Ratio As Single
  newStrFileName = FilePath & newStrFileName & ".jpg"
  wmFont = New Font("Verdana", 6, FontStyle.Bold)
  DesiredWidth = bmp.Width * .75
  StringSizeF = canvas.MeasureString(strWatermark, wmFont)
  Ratio = StringSizeF.Width / wmFont.SizeInPoints
  RequiredFontSize = DesiredWidth / Ratio
  wmFont = New Font("Verdana", RequiredFontSize, FontStyle.Bold)
  canvas.DrawString(strWatermark, wmFont, New SolidBrush(Color.Beige), 0, 0)
  canvas.DrawString(strWatermark, wmFont, New SolidBrush(Color.FromArgb(128, 0, 0, 0)), 2, 2)
  canvas.DrawString(strWatermark, wmFont, New SolidBrush(Color.FromArgb(128, 255, 255, 255)), 0, 0)
  canvas.DrawString(strWatermark, wmFont, New SolidBrush(Color.FromArgb(128, 0, 0, 0)), 2, 2)
  canvas.DrawString(strWatermark, wmFont, New SolidBrush(Color.FromArgb(128, 255, 255, 255)), 0, 0)
  bmp.SetResolution(96, 96)
  bmp.Save(newStrFileName,ImageFormat.Jpeg)
  canvas.dispose()
  bmp.dispose()
End Function


现在,我在编辑这些函数之前就已经对其进行了编辑,因此,如果存在缺陷,请通知我,因为我没有时间对其进行测试.无论如何,您需要先保存上传的图像,或者至少知道要添加水印或调整大小的图像的位置.有关如何使用它们的示例如下:

''''调整大小
''''如果希望在功能命令中包含".jpg",请从
中将其删除 在该函数中,您可以拥有"resizeme.jpg"和"resize.jpg"
generateThumbnail(100,"resizeme","resize")
''''水印
''''如果希望在功能命令中包含".jpg",请从
中将其删除 在该函数中,您可以拥有"watermarkme.jpg"和"watermarked.jpg"
水印("watermarkme",带水印")
这些功能仅执行JPEGS,因此,如果尝试其他文件格式,它将对您失败.


Now these functions I have edited before I put on here, so if there''s a flaw let me know as I haven''t had time to test them. Anyway, you need to save your uploaded image first, or at least know the location of the ones you want to watermark or resize. An example on how to use these are:

''''resize
''''if you wish to have the ".jpg" within the function command, remove it from
''''within the function and you can have "resizeme.jpg" and "resized.jpg"
generateThumbnail(100,"resizeme","resized")
''''watermark
''''if you wish to have the ".jpg" within the function command, remove it from
''''within the function and you can have "watermarkme.jpg" and "watermarked.jpg"
watermark("watermarkme","watermarked")
These functions only do JPEGS, so if you try another file format, it will fail on you.


这篇关于在图像上加水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆