您好,登錄后才能下訂單哦!
VB.NET中怎么讀取圖像,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
VB.NET讀取圖像代碼示例:
Public Function GetImageFromFile()
Function GetImageFromFile(ByVal
pstrFileName As String) As Boolean
Dim strExt As String = "" '擴展文件名
Dim blnFlag As Boolean = False
If ((pstrFileName.IndexOf(":")
< 0) AndAlso (Not PictureHolder.
mstrPath Is Nothing)) Then
pstrFileName = (PictureHolder.
mstrPath & pstrFileName)
End If
If Not File.Exists(pstrFileName) Then
Return False
End If
VB.NET讀取圖像取得擴展名
strExt = Path.GetExtension
(pstrFileName).ToLowerIf strExt.Equals(".cur") Then
Try
Dim cursor As New Windows.Forms.
Cursor(pstrFileName)Dim targetRect As New Rectangle
(New Point(0, 0), cursor.Size)Me.mobjImage = New Bitmap(cursor
.Size.Width, cursor.Size.Height)Dim g As GraphicsGraphics =
Graphics.FromImage(Me.mobjImage)cursor.Draw(g, targetRect)
cursor.Dispose()
Return True
Catch obj1 As Exception
Return False
End Try
End If
Try
Using stream As IO.FileStream = New IO.
FileStream(pstrFileName, FileMode.
Open, FileAccess.Read)Dim stream2 As New IO.MemoryStream
Do While True
Dim count As Integer = stream.Read
(PictureHolder.mbtyImage, 0,
PictureHolder.mbtyImage.Length)If (count = 0) Then
Exit Do
End If
stream2.Write(PictureHolder.
mbtyImage, 0, count)Loop
stream2.Flush()
stream2.Position = 0
若為 ico 類型,則使用 Drawing.Icon 打開圖像
If strExt.Equals(".ico") Then
Me.mobjImage = New Drawing.
Icon(stream2).ToBitmapElse
Me.mobjImage = Drawing.Image.
FromStream(stream2)End If
blnFlag = True
End Using
Catch obj2 As Exception
blnFlag = False
End Try
Return blnFlag
End Function
看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。