引用页的代码:
?
Imports dll图片水印缩略图
Partial Class _Default
??? Inherits System.Web.UI.Page
??? Private imageutile As dell图片缩略图水印 = New dell图片缩略图水印
??? Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
??????? Dim imagehz As String() = {".jpg", ".jpge", ".png", ".gif", ".bmp"}
??????? '(ByVal Fup上传控件 As FileUpload, ByVal strimage As String(), ByVal image缩略图 As Image, ByVal lab错误提示
??????? 'str水印图片路径 As String, ByVal str图片保存路径 As String, ByVal str水印文字 As String, ByVal x水印坐标 As Integer, ByVal y水印坐标 As Integer, ByVal 缩略图高 As String, ByVal 缩略图宽 As String, ByVal 文字 As Boolean, ByVal 图片 As Boolean
??????? Me.imageutile.upimage图片上传设置水印(Me.FileUpload1, imagehz, Me.Image1, Me.Label1, "image/logo.jpg", "imagelocal", "weizhigan", 30, 30, 100, 150, True, False)
??? End Sub
End Class
附加库文件下载和测试工程下载
dll的代码在公司了,今天写完dll的代码后直接拷贝dll文件回来而已,代码没拷贝回来
如果对dll代码感兴趣的给我留言留下你的邮件我发给各位
早上忙,没能补dll的代码上来现在发布
Public Class dell图片缩略图水印
??? '
??? '
??? '上传图片缩略
??? Sub upimage图片上传设置水印(ByVal Fup上传控件 As FileUpload, ByVal strimage As String(), ByVal image缩略图
As Image, ByVal lab错误提示 As Label, ByVal str水印图片路径 As String, ByVal str图片保存路径 As String, ByVal str
水印文字 As String, ByVal x水印坐标 As Integer, ByVal y水印坐标 As Integer, ByVal 缩略图高 As String, ByVal 缩略图
宽 As String, ByVal 文字 As Boolean, ByVal 图片 As Boolean)
??????? Dim imagelocal = str图片保存路径 ' "~/imagelocal"
??????? Dim iname As String ' 文件保存名
??????? Dim flash是否继续 As Boolean = False
??????? If Not (Fup上传控件.PostedFile Is Nothing) Then '上传的图片不为空的时候进行一下操作
??????????? Dim namestr1 As String = (Fup上传控件.PostedFile.FileName) '获取上传的文件名
??????????? Dim j As Integer = namestr1.LastIndexOf(".")
??????????? Dim newname As String = namestr1.Substring(j) '图片得到后辍名
??????????? For k As Int32 = 0 To strimage.Length - 1 Step 1
??????????????? If newname = strimage(k) Then
??????????????????? flash是否继续 = True '
??????????????? End If
??????????? Next k
??????????? If flash是否继续 Then
??????????????? iname = CStr(Now.ToFileTimeUtc) '随机的文件名(不会重复)
??????????????? Dim newnames As String = iname + newname '重新组合文件名
??????????????? '是否保存原图?
??????????????? 'Fup上传控件.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath(imagelocal) + "/" +
newnames) '保存文件到文件夹
??????????????? Dim image, sImage, stimgs As System.Drawing.Image
??????????????? image = System.Drawing.Image.FromStream(Fup上传控件.PostedFile.InputStream) '得到原图
??????????????? Dim imagelocals As String = HttpRuntime.AppDomainAppPath
??????????????? Dim files As New System.IO.FileStream(imagelocals + "/" + str水印图片路径, IO.FileMode.Open,
IO.FileAccess.ReadWrite) '实例化FileStream类()
??????????????? stimgs = System.Drawing.Image.FromStream(files) '即将把获得的水印图流写入
??????????????? files.Close() '关闭流
??????????????? Dim width As Decimal = image.Width '得到原图的宽
??????????????? Dim height As Decimal = image.Height '得到原图的高
??????????????? Dim swidth As Decimal = stimgs.Width
??????????????? Dim sheight As Decimal = stimgs.Height
??????????????? Dim newwidth, newheight As Integer '定义缩略图的大小
??????????????? If 缩略图高 > 0 And 缩略图宽 > 0 Then
??????????????????? newwidth = 缩略图宽
??????????????????? newheight = 缩略图高
??????????????? Else
??????????????????? '计算缩略图的大小
??????????????????? If (width > height) Then
??????????????????????? newwidth = 150
??????????????????????? newheight = CInt(height / width * 150)
??????????????????? Else
??????????????????????? newheight = 150
??????????????????????? newwidth = CInt(width / height * 150)
??????????????????? End If
??????????????? End If
??????????????? sImage = image '.GetThumbnailImage(width, height, Nothing, IntPtr.Zero) '返回image的缩略图
??????????????? Dim output As Drawing.Bitmap = New Drawing.Bitmap(sImage) '设置缩略图为位图
??????????????? Dim g As Drawing.Graphics = Drawing.Graphics.FromImage(output) '即将用绘画类画出图片
??????????????? '设计文字水印的位置
??????????????? '如果没有设定文字水印坐标就进行默认位置
??????????????? Dim x As Integer = x水印坐标
??????????????? Dim y As Integer = y水印坐标
??????????????? Dim fonts As New Drawing.Font("Tw Cen MT", 18) '默认的水印字体和大小
??????????????? '给缩略图加上文字水印
??????????????? '如果设置了文字水印
??????????????? If 文字 Then
??????????????????? If str水印文字 = "" Then
??????????????????????? g.DrawString("顶佳技术中心", fonts, New Drawing.SolidBrush(Drawing.Color.Red), (width - x),
(height - y)) '给图片设置文字水印
??????????????????? Else
??????????????????????? g.DrawString(str水印文字, fonts, New Drawing.SolidBrush(Drawing.Color.Red), (width - x), (height -
y)) '给图片设置文字水印
??????????????????? End If
??????????????? End If
??????????????? '给缩略图加上图片水印
??????????????? '如果设置了图片水印
??????????????? If 图片 Then
??????????????????? If str水印图片路径 = "" Then
??????????????????????? g.DrawString("顶佳软件提醒你:图片未找到!", fonts, New Drawing.SolidBrush(Drawing.Color.Red),
(width - x), (height - y)) '给图片设置文字水印
??????????????????? Else
??????????????????????? g.DrawImage(stimgs, (width - swidth - x), (height - sheight - y)) '给图片设置图片水印
??????????????????? End If
??????????????? End If
??????????????? output.Save(System.Web.HttpContext.Current.Server.MapPath(imagelocal) + "/s_" + newnames,
System.Drawing.Imaging.ImageFormat.Jpeg)
??????????????? '保存缩略图到Simagelocal文件夹
??????????????? image缩略图.Height = newheight
??????????????? image缩略图.Width = newwidth
??????????????? image缩略图.Visible = True
??????????????? image缩略图.ImageUrl = "../" + imagelocal + "/s_" + newnames
??????????? Else
??????????????? lab错误提示.Text = "你要上传的图片不符合类型"
??????????? End If
??????? End If
??? End Sub
End Class