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

问题描述

你好,

我想开发一个在线应用程序,用户可以在图像上输入任何单词(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,

推荐答案


<![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.


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

08-31 05:43