VB.NET可以对图片进行熟练的操作。比如对图片进行合并或分开等等。在这里我们会为大家介绍一下有关VB.NET相框效果的实现方法,希望可以帮助大家提高对图片处理方面的认知程度。#t#
VB.NET相框效果实现代码示例:
- 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
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
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
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
测试VB.NET相框效果代码
'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("错误")
'End If
End Function
End Class
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
VB.NET相框效果的相关操作方法就为大家介绍到这里。