日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

vb.net 如何从文件中读取图像

發布時間:2025/7/25 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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
??????
'取得擴展名
??????strExt?=?Path.GetExtension(pstrFileName).ToLower
??????
If?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?Graphics?=?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).ToBitmap
??????????
Else
????????????
Me.mobjImage?=?Drawing.Image.FromStream(stream2)
??????????
End?If
??????????blnFlag?
=?True
????????
End?Using
??????
Catch?obj2?As?Exception
????????blnFlag?
=?False
??????
End?Try
??????
Return?blnFlag
????
End?Function

轉載于:https://www.cnblogs.com/betterfar/archive/2008/06/14/1220963.html

總結

以上是生活随笔為你收集整理的vb.net 如何从文件中读取图像的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。