VB.NET中怎么讀取圖像,很多新手對此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
站在用戶的角度思考問題,與客戶深入溝通,找到寶清網(wǎng)站設(shè)計(jì)與寶清網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站制作、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋寶清地區(qū)。
VB.NET讀取圖像代碼示例:
Public Function GetImageFromFile()
Function GetImageFromFile(ByVal
pstrFileName As String) As Boolean
Dim strExt As String = "" '擴(kuò)展文件名
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讀取圖像取得擴(kuò)展名
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)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)的支持。