📄 form1.vb
字号:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents picImage As System.Windows.Forms.PictureBox
Friend WithEvents picWatermark As System.Windows.Forms.PictureBox
Friend WithEvents picWatermark2 As System.Windows.Forms.PictureBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.picImage = New System.Windows.Forms.PictureBox
Me.picWatermark = New System.Windows.Forms.PictureBox
Me.picWatermark2 = New System.Windows.Forms.PictureBox
Me.SuspendLayout()
'
'picImage
'
Me.picImage.Image = CType(resources.GetObject("picImage.Image"), System.Drawing.Image)
Me.picImage.Location = New System.Drawing.Point(8, 8)
Me.picImage.Name = "picImage"
Me.picImage.Size = New System.Drawing.Size(412, 270)
Me.picImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
Me.picImage.TabIndex = 0
Me.picImage.TabStop = False
'
'picWatermark
'
Me.picWatermark.Image = CType(resources.GetObject("picWatermark.Image"), System.Drawing.Image)
Me.picWatermark.Location = New System.Drawing.Point(0, 0)
Me.picWatermark.Name = "picWatermark"
Me.picWatermark.Size = New System.Drawing.Size(243, 63)
Me.picWatermark.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
Me.picWatermark.TabIndex = 1
Me.picWatermark.TabStop = False
Me.picWatermark.Visible = False
'
'picWatermark2
'
Me.picWatermark2.Image = CType(resources.GetObject("picWatermark2.Image"), System.Drawing.Image)
Me.picWatermark2.Location = New System.Drawing.Point(0, 72)
Me.picWatermark2.Name = "picWatermark2"
Me.picWatermark2.Size = New System.Drawing.Size(243, 63)
Me.picWatermark2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
Me.picWatermark2.TabIndex = 2
Me.picWatermark2.TabStop = False
Me.picWatermark2.Visible = False
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(424, 285)
Me.Controls.Add(Me.picWatermark2)
Me.Controls.Add(Me.picWatermark)
Me.Controls.Add(Me.picImage)
Me.Name = "Form1"
Me.Text = "Watermark"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim watermark_bm As New Bitmap(picWatermark.Image)
Dim result_bm As New Bitmap(picImage.Image)
Dim x As Integer = (result_bm.Width - watermark_bm.Width) \ 2
Dim y As Integer = (result_bm.Height - watermark_bm.Height) \ 3
DrawWatermark(watermark_bm, result_bm, x, y)
watermark_bm = New Bitmap(picWatermark2.Image)
y = 2 * (result_bm.Height - watermark_bm.Height) \ 3
DrawWatermark(watermark_bm, result_bm, x, y)
picImage.Image = result_bm
End Sub
' Copy the watermark image over the result image.
Private Sub DrawWatermark(ByVal watermark_bm As Bitmap, ByVal result_bm As Bitmap, ByVal x As Integer, ByVal y As Integer)
Const ALPHA As Byte = 128
' Set the watermark's pixels' Alpha components.
Dim clr As Color
For py As Integer = 0 To watermark_bm.Height - 1
For px As Integer = 0 To watermark_bm.Width - 1
clr = watermark_bm.GetPixel(px, py)
watermark_bm.SetPixel(px, py, Color.FromArgb(ALPHA, clr.R, clr.G, clr.B))
Next px
Next py
' Set the watermark's transparent color.
watermark_bm.MakeTransparent(watermark_bm.GetPixel(0, 0))
' Copy onto the result image.
Dim gr As Graphics = Graphics.FromImage(result_bm)
gr.DrawImage(watermark_bm, x, y)
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -