ASP.NET(VB) 給圖片增加浮水印文字

來源:互聯網
上載者:User

'指定要添加浮水印文字的圖片
Dim img As Image = Image.FromFile(Server.MapPath("~/upload/1.jpg"))
'建立一個位元影像對象以供繪圖操作(不能直接操作 BMP 以外的格式,可能吧)
Dim bitmap As New Bitmap(343, 498)
'要繪製文字的字型
Dim f As New Font("微軟雅黑", 16, FontStyle.Underline)
'文字內容
Dim str As String = TextBox5.Text
'建立一個繪製映像的對象
Dim g As Graphics = Graphics.FromImage(bitmap)
'線條的座標
Dim x1, x2, y1, y2, s1, s2 As Integer
x1 = CType(TextBox1.Text, Integer)
x2 = CType(TextBox2.Text, Integer)
y1 = CType(TextBox3.Text, Integer)
y2 = CType(TextBox4.Text, Integer)
'文字的座標
s1 = CType(TextBox6.Text, Integer)
s2 = CType(TextBox7.Text, Integer)
'限定繪圖的範圍
g.DrawImage(img, 0, 0, 343, 498)
'繪製文字
g.DrawString(str, f, Brushes.Red, s1, s2)
'繪製線條
g.DrawLine(Pens.White, x1, x2, y1, y2)
'繪製完成後的儲存路徑
Dim iimg As String = "~/upload/11.jpg"
Dim img1 As String = Server.MapPath(iimg)
'JPG 映像品質參數
Dim ep As Imaging.EncoderParameters = New Imaging.EncoderParameters
'映像品質值
ep.Param(0) = New Imaging.EncoderParameter(Imaging.Encoder.Quality, CLng(TextBox8.Text))
'以流方式讀取映像內容
Dim codecs As Imaging.ImageCodecInfo() = Imaging.ImageCodecInfo.GetImageEncoders
Dim ici As Imaging.ImageCodecInfo
For Each codec As Imaging.ImageCodecInfo In codecs
If codec.MimeType = "image/jpeg" Then
ici = codec
End If
Next
'儲存繪製好的映像
bitmap.Save(img1, ici, ep)
Image1.ImageUrl = iimg
'釋放對象
g.Dispose()
bitmap.Dispose()
img.Dispose()

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.