VB.NET相框效果具體方式解析
作者:佚名
VB.NET相框效果的實(shí)現(xiàn)主要體現(xiàn)在講圖片進(jìn)行合并。那么具體的代碼又該如何編寫(xiě)呢?在這里就為大家詳細(xì)介紹一下這方面的編寫(xiě)技巧。
VB.NET可以對(duì)圖片進(jìn)行熟練的操作。比如對(duì)圖片進(jìn)行合并或分開(kāi)等等。在這里我們會(huì)為大家介紹一下有關(guān)VB.NET相框效果的實(shí)現(xiàn)方法,希望可以幫助大家提高對(duì)圖片處理方面的認(rèn)知程度。#t#
VB.NET相框效果實(shí)現(xiàn)代碼示例:
- 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
測(cè)試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("錯(cuò)誤")
- 'End If
- End Function
- End Class
VB.NET相框效果的相關(guān)操作方法就為大家介紹到這里。
責(zé)任編輯:曹凱
來(lái)源:
博客園