小编给大家分享一下VB.NET如何实现相框效果,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!VB.net相框效果实现代码示例:Imports Syste
小编给大家分享一下VB.NET如何实现相框效果,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
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
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
测试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
以上是“VB.NET如何实现相框效果”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网精选频道!
--结束END--
本文标题: VB.NET如何实现相框效果
本文链接: https://lsjlt.com/news/291496.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0