Dim img As Image = Image.FromFile(FileName)
Dim g = Graphics.FromImage(img)
Dim MyFont = New Font("微软雅黑", Y)
Dim MyBrush As New SolidBrush(Color.White)
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.GammaCorrected
g.DrawString(“水印文字”, MyFont, MyBrush, X, Y)
文字定位之前可以使用 Dim siF As SizeF = g.MeasureString(Me.TextBox7.Text, MyFont4) 先确定文字的尺寸,再计算文字的位置
给图片加图片水印
Private Sub DrawImageWH(ByVal imgDest as Bitmap, ByVal logoFileName As String, ByVal logoLeft As Integer, ByVal logoTop As Integer, ByVal logoOpacity As Single, ByVal W As Integer, ByVal H As Integer)
logoImg = Image.FromFile(logoFileName)
NewLogo = ImgReSize(logoImg.Clone, W, H)'根据需要调整Logo水印的尺寸
Dim g As Graphics = Graphics.FromImage(imgDest)
Dim matrixArray()() As Single = {
New Single() {1, 0, 0, 0, 0},
New Single() {0, 1, 0, 0, 0},
New Single() {0, 0, 1, 0, 0},
New Single() {0, 0, 0, logoOpacity, 0},
New Single() {0, 0, 0, 0, 1}}
Dim cMatrix As New Imaging.ColorMatrix(matrixArray)
Dim imgAttr As New Imaging.ImageAttributes()
imgAttr.SetColorMatrix(cMatrix, Imaging.ColorMatrixFlag.Default, Imaging.ColorAdjustType.Bitmap)
Dim recDest As New Rectangle(logoLeft, logoTop, NewLogo.Width, NewLogo.Height)
g.DrawImage(NewLogo, recDest, 0, 0, NewLogo.Width, NewLogo.Height, GraphicsUnit.Pixel, imgAttr)
g.Dispose()
PictureBox1.Image = imgDest
End Sub
[本日志由 tiancao1001 于 2023-11-23 04:41 PM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |