Revert MyBitmap.vb
This commit is contained in:
@@ -64,28 +64,23 @@ Public Class MyBitmap
|
|||||||
BitmapCache.Add(FilePathOrResourceName, Pic)
|
BitmapCache.Add(FilePathOrResourceName, Pic)
|
||||||
End If
|
End If
|
||||||
Else
|
Else
|
||||||
Dim InputStream As Stream
|
|
||||||
If FilePathOrResourceName.StartsWithF("http") Then '在线图片(这里判断 https:\\ 或 http:\\ 会出问题)
|
|
||||||
Dim Client = New Net.WebClient()
|
|
||||||
InputStream = New MemoryStream(Client.DownloadData(FilePathOrResourceName))
|
|
||||||
Else
|
|
||||||
InputStream = New MemoryStream(File.ReadAllBytes(FilePathOrResourceName))
|
|
||||||
End If
|
|
||||||
'使用这种自己接管 FileStream 的方法加载才能解除文件占用
|
'使用这种自己接管 FileStream 的方法加载才能解除文件占用
|
||||||
'判断是否为 WebP 文件头
|
Using InputStream As New FileStream(FilePathOrResourceName, FileMode.Open)
|
||||||
Dim Header(1) As Byte
|
'判断是否为 WebP 文件头
|
||||||
InputStream.Read(Header, 0, 2)
|
Dim Header(1) As Byte
|
||||||
InputStream.Seek(0, SeekOrigin.Begin)
|
InputStream.Read(Header, 0, 2)
|
||||||
If Header(0) = 82 AndAlso Header(1) = 73 Then
|
InputStream.Seek(0, SeekOrigin.Begin)
|
||||||
'读取 WebP
|
If Header(0) = 82 AndAlso Header(1) = 73 Then
|
||||||
If Is32BitSystem Then Throw New Exception("不支持在 32 位系统下加载 WebP 图片。")
|
'读取 WebP
|
||||||
Dim FileBytes(InputStream.Length - 1) As Byte
|
If Is32BitSystem Then Throw New Exception("不支持在 32 位系统下加载 WebP 图片。")
|
||||||
InputStream.Read(FileBytes, 0, FileBytes.Length)
|
Dim FileBytes(InputStream.Length - 1) As Byte
|
||||||
Dim Decoder As New Imazen.WebP.SimpleDecoder()
|
InputStream.Read(FileBytes, 0, FileBytes.Length)
|
||||||
Pic = Decoder.DecodeFromBytes(FileBytes, FileBytes.Length)
|
Dim Decoder As New Imazen.WebP.SimpleDecoder()
|
||||||
Else
|
Pic = Decoder.DecodeFromBytes(FileBytes, FileBytes.Length)
|
||||||
Pic = New System.Drawing.Bitmap(InputStream)
|
Else
|
||||||
End If
|
Pic = New System.Drawing.Bitmap(InputStream)
|
||||||
|
End If
|
||||||
|
End Using
|
||||||
End If
|
End If
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Pic = My.Application.TryFindResource(FilePathOrResourceName)
|
Pic = My.Application.TryFindResource(FilePathOrResourceName)
|
||||||
@@ -157,4 +152,4 @@ Public Class MyBitmap
|
|||||||
End Using
|
End Using
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
End Class
|
End Class
|
||||||
Reference in New Issue
Block a user