How to realize the effect of photo frame with VB.NET
Editor to share with you how to achieve the picture frame effect of VB.NET, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
VB.NET photo frame effect implementation code example:
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Public Class ImgMerg
Public Shared Function MergedImage
(ByVal innerImgPath As String
ByVal outerImgPath As String
ByVal mergImgPath As String)
As Boolean
Try
Dim fi As System.IO.FileInfo =
New System.IO.FileInfo (mergImgPath)
If fi.Directory.Exists = False Then
Fi.Directory.Create ()
End If
Dim innerImg As ImageImage = Image.
FromFile (innerImgPath)
Dim outerImg As ImageImage = Image.
FromFile (outerImgPath)
Dim b As New Bitmap (outerImg.Width
OuterImg.Height, PixelFormat.
Format16bppRgb555)
Dim g As GraphicsGraphics =
Graphics.FromImage (b)
G.Clear (Color.White)
Dim p1 (2) As Point
Dim p2 (2) As Point
If outerImg.Width > = innerImg.Width Then
If outerImg.Height > = innerImg.Height Then
P1 (0) = New Point ((outerImg.Width-
InnerImg.Width)\ 2, (outerImg.Height-
InnerImg.Height)\ 2)
P1 (1) = New Point ((outerImg.Width +)
InnerImg.Width)\ 2, (outerImg.
Height-innerImg.Height)\ 2)
P1 (2) = New Point ((outerImg.Width-
InnerImg.Width)\ 2, (outerImg.Height +
InnerImg.Height)\ 2)
Else
P1 (0) = New Point ((outerImg.Width-
InnerImg.Width)\ 2, 0)
P1 (1) = New Point ((outerImg.Width +)
InnerImg.Width)\ 2, 0)
P1 (2) = New Point ((outerImg.Width-
InnerImg.Width)\ 2, outerImg.Height)
End If
Else
If outerImg.Height > = innerImg.Height Then
P1 (0) = New Point (0, (outerImg.Height)
-innerImg.Height)\ 2)
P1 (1) = New Point (outerImg.Width
(outerImg.Height-innerImg.Height)\ 2)
P1 (2) = New Point (0, (outerImg.Height)
+ innerImg.Height)\ 2)
Else
P1 (0) = New Point (0,0)
P1 (1) = New Point (outerImg.Width, 0)
P1 (2) = New Point (0, outerImg.Height)
End If
End If
P2 (0) = New Point (0,0)
P2 (1) = New Point
(outerImg.Width, 0)
P2 (2) = New Point
(0, outerImg.Height)
G.DrawImage (innerImg, p1)
G.DrawImage (outerImg, p2)
B.Save (mergImgPath)
OuterImg.Dispose ()
InnerImg.Dispose ()
Return True
Catch ex As Exception
Return False
End Try
Test the VB.NET photo frame effect code
'Dim innerImgPath As String =
"c:\ Winter.jpg"
'Dim outerImgPath As String =
"c:\ 17.gif"
'Dim savePath As String =
"C:\ merg.jpg"
'If ImgMerg.MergedImage
(innerImgPath, outerImgPath
SavePath) = True Then
'Dim bMerg As New System.
Drawing.Bitmap (savePath)
'Else
'MsgBox ("error")
'End If
End Function
End Class
The above is all the content of the article "how to achieve Photo frame effect in VB.NET". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!