十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
VB.NET中怎么读取图像,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
站在用户的角度思考问题,与客户深入沟通,找到宝清网站设计与宝清网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站制作、网站建设、企业官网、英文网站、手机端网站、网站推广、域名注册、雅安服务器托管、企业邮箱。业务覆盖宝清地区。
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
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。