VB.NET中怎么读取图像

发布时间:2021-07-19 16:10:00 作者:Leah
来源:亿速云 阅读:505

VB.NET中怎么读取图像,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

VB.NET读取图像代码示例:

  1. Public Function GetImageFromFile()
    Function GetImageFromFile(ByVal 
    pstrFileName As String) As Boolean  

  2. Dim strExt As String = "" '扩展文件名  

  3. Dim blnFlag As Boolean = False 

  4. If ((pstrFileName.IndexOf(":") 
    < 0) AndAlso (Not PictureHolder.
    mstrPath Is Nothing)) Then  

  5. pstrFileName = (PictureHolder.
    mstrPath & pstrFileName)  

  6. End If  

  7. If Not File.Exists(pstrFileName) Then  

  8. Return False  

  9. End If 

VB.NET读取图像取得扩展名

  1. strExt = Path.GetExtension
    (pstrFileName).ToLower  

  2. If strExt.Equals(".cur") Then  

  3. Try  

  4. Dim cursor As New Windows.Forms.
    Cursor(pstrFileName)  

  5. Dim targetRect As New Rectangle
    (New Point(0, 0), cursor.Size)  

  6. Me.mobjImage = New Bitmap(cursor
    .Size.Width, cursor.Size.Height)  

  7. Dim g As GraphicsGraphics = 
    Graphics.FromImage(Me.mobjImage)  

  8. cursor.Draw(g, targetRect)  

  9. cursor.Dispose()  

  10. Return True  

  11. Catch obj1 As Exception  

  12. Return False  

  13. End Try  

  14. End If  

  15. Try  

  16. Using stream As IO.FileStream = New IO.
    FileStream(pstrFileName, FileMode.
    Open, FileAccess.Read)  

  17. Dim stream2 As New IO.MemoryStream  

  18. Do While True  

  19. Dim count As Integer = stream.Read
    (PictureHolder.mbtyImage, 0, 
    PictureHolder.mbtyImage.Length)  

  20. If (count = 0) Then  

  21. Exit Do  

  22. End If  

  23. stream2.Write(PictureHolder.
    mbtyImage, 0, count)  

  24. Loop  

  25. stream2.Flush()  

  26. stream2.Position = 0 

若为 ico 类型,则使用 Drawing.Icon 打开图像

  1. If strExt.Equals(".ico") Then  

  2. Me.mobjImage = New Drawing.
    Icon(stream2).ToBitmap  

  3. Else  

  4. Me.mobjImage = Drawing.Image.
    FromStream(stream2)  

  5. End If  

  6. blnFlag = True 

  7. End Using  

  8. Catch obj2 As Exception  

  9. blnFlag = False 

  10. End Try  

  11. Return blnFlag  

  12. End Function 

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

推荐阅读:
  1. 怎么在Python中利用matplotlib读取图像
  2. JavaScript如何使用readAsDataURL读取图像文件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vb.net

上一篇:VB.NET中怎么获取二进制图像

下一篇:python中的EasyOCR库是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》