Skip to content

Commit

Permalink
fix: 不使用磁盘缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
tangge233 committed Oct 3, 2024
1 parent e782d0e commit 788f7c9
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions Plain Craft Launcher 2/Modules/Base/MyBitmap.vb
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,28 @@ Public Class MyBitmap
BitmapCache.Add(FilePathOrResourceName, Pic)
End If
Else
Dim InputStream As Stream
If FilePathOrResourceName.StartsWithF("http") Then '在线图片(这里判断 https:\\ 或 http:\\ 会出问题)
Dim tempFile = PathTemp & "Cache\MyImage\" & GetHash(FilePathOrResourceName)
NetDownload(FilePathOrResourceName, tempFile, True)
FilePathOrResourceName = tempFile
Dim Client = New Net.WebClient()
InputStream = New MemoryStream(Client.DownloadData(FilePathOrResourceName))
Else
InputStream = New MemoryStream(File.ReadAllBytes(FilePathOrResourceName))
End If
'使用这种自己接管 FileStream 的方法加载才能解除文件占用
Using InputStream As New FileStream(FilePathOrResourceName, FileMode.Open)
'判断是否为 WebP 文件头
Dim Header(1) As Byte
InputStream.Read(Header, 0, 2)
InputStream.Seek(0, SeekOrigin.Begin)
If Header(0) = 82 AndAlso Header(1) = 73 Then
'读取 WebP
If Is32BitSystem Then Throw New Exception("不支持在 32 位系统下加载 WebP 图片。")
Dim FileBytes(InputStream.Length - 1) As Byte
InputStream.Read(FileBytes, 0, FileBytes.Length)
Dim Decoder As New Imazen.WebP.SimpleDecoder()
Pic = Decoder.DecodeFromBytes(FileBytes, FileBytes.Length)
Else
Pic = New System.Drawing.Bitmap(InputStream)
End If
End Using
'判断是否为 WebP 文件头
Dim Header(1) As Byte
InputStream.Read(Header, 0, 2)
InputStream.Seek(0, SeekOrigin.Begin)
If Header(0) = 82 AndAlso Header(1) = 73 Then
'读取 WebP
If Is32BitSystem Then Throw New Exception("不支持在 32 位系统下加载 WebP 图片。")
Dim FileBytes(InputStream.Length - 1) As Byte
InputStream.Read(FileBytes, 0, FileBytes.Length)
Dim Decoder As New Imazen.WebP.SimpleDecoder()
Pic = Decoder.DecodeFromBytes(FileBytes, FileBytes.Length)
Else
Pic = New System.Drawing.Bitmap(InputStream)
End If
End If
Catch ex As Exception
Pic = My.Application.TryFindResource(FilePathOrResourceName)
Expand Down

0 comments on commit 788f7c9

Please sign in to comment.