fix: 不使用磁盘缓存
This commit is contained in:
@@ -64,28 +64,28 @@ 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:\\ 会出问题)
|
If FilePathOrResourceName.StartsWithF("http") Then '在线图片(这里判断 https:\\ 或 http:\\ 会出问题)
|
||||||
Dim tempFile = PathTemp & "Cache\MyImage\" & GetHash(FilePathOrResourceName)
|
Dim Client = New Net.WebClient()
|
||||||
NetDownload(FilePathOrResourceName, tempFile, True)
|
InputStream = New MemoryStream(Client.DownloadData(FilePathOrResourceName))
|
||||||
FilePathOrResourceName = tempFile
|
Else
|
||||||
|
InputStream = New MemoryStream(File.ReadAllBytes(FilePathOrResourceName))
|
||||||
End If
|
End If
|
||||||
'使用这种自己接管 FileStream 的方法加载才能解除文件占用
|
'使用这种自己接管 FileStream 的方法加载才能解除文件占用
|
||||||
Using InputStream As New FileStream(FilePathOrResourceName, FileMode.Open)
|
'判断是否为 WebP 文件头
|
||||||
'判断是否为 WebP 文件头
|
Dim Header(1) As Byte
|
||||||
Dim Header(1) As Byte
|
InputStream.Read(Header, 0, 2)
|
||||||
InputStream.Read(Header, 0, 2)
|
InputStream.Seek(0, SeekOrigin.Begin)
|
||||||
InputStream.Seek(0, SeekOrigin.Begin)
|
If Header(0) = 82 AndAlso Header(1) = 73 Then
|
||||||
If Header(0) = 82 AndAlso Header(1) = 73 Then
|
'读取 WebP
|
||||||
'读取 WebP
|
If Is32BitSystem Then Throw New Exception("不支持在 32 位系统下加载 WebP 图片。")
|
||||||
If Is32BitSystem Then Throw New Exception("不支持在 32 位系统下加载 WebP 图片。")
|
Dim FileBytes(InputStream.Length - 1) As Byte
|
||||||
Dim FileBytes(InputStream.Length - 1) As Byte
|
InputStream.Read(FileBytes, 0, FileBytes.Length)
|
||||||
InputStream.Read(FileBytes, 0, FileBytes.Length)
|
Dim Decoder As New Imazen.WebP.SimpleDecoder()
|
||||||
Dim Decoder As New Imazen.WebP.SimpleDecoder()
|
Pic = Decoder.DecodeFromBytes(FileBytes, FileBytes.Length)
|
||||||
Pic = Decoder.DecodeFromBytes(FileBytes, FileBytes.Length)
|
Else
|
||||||
Else
|
Pic = New System.Drawing.Bitmap(InputStream)
|
||||||
Pic = New System.Drawing.Bitmap(InputStream)
|
End If
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user