Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MyImage 控件 #4868

Merged
merged 13 commits into from
Oct 13, 2024
34 changes: 34 additions & 0 deletions Plain Craft Launcher 2/Controls/MyImage.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Public Class MyImage
Inherits Image

'事件

Public Uuid As Integer = GetUuid()
tangge233 marked this conversation as resolved.
Show resolved Hide resolved

Private _SourceData As String = ""

''' <summary>
''' 重写Image的Source属性
''' </summary>
Public Shadows Property Source As String
Get
Return _SourceData
End Get
Set(value As String)
SetImage(value)
tangge233 marked this conversation as resolved.
Show resolved Hide resolved
End Set
End Property
Public Shared Shadows ReadOnly SourceProperty As DependencyProperty = DependencyProperty.Register("Source", GetType(String), GetType(MyImage), New PropertyMetadata(New PropertyChangedCallback(
Sub(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
If Not IsNothing(sender) Then
CType(sender, MyImage).SetImage(e.NewValue)
End If
End Sub)))

Private Sub SetImage(source As String)
If Me Is Nothing Then Exit Sub
If String.IsNullOrEmpty(source) Then Exit Sub
_SourceData = source
MyBase.Source = New MyBitmap(_SourceData)
End Sub
End Class
12 changes: 12 additions & 0 deletions Plain Craft Launcher 2/Modules/Base/MyBitmap.vb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ Public Class MyBitmap
BitmapCache.Add(FilePathOrResourceName, Pic)
End If
Else
If FilePathOrResourceName.StartsWithF("http") Then '在线图片(这里判断 https:\\ 或 http:\\ 会出问题)
Dim tempFile = PathTemp & "Cache\MyImage\" & GetHash(FilePathOrResourceName)
tangge233 marked this conversation as resolved.
Show resolved Hide resolved
NetDownload(FilePathOrResourceName, tempFile, True)
FilePathOrResourceName = tempFile
ElseIf FilePathOrResourceName.StartsWithF("data:image/png;base64,") Then 'base64 图片
Dim base64Data = FilePathOrResourceName.Split(",")(1)
Dim imageData = Convert.FromBase64String(base64Data)
Using ms = New MemoryStream(imageData)
Pic = New System.Drawing.Bitmap(ms)
End Using
Return
End If
'使用这种自己接管 FileStream 的方法加载才能解除文件占用
Using InputStream As New FileStream(FilePathOrResourceName, FileMode.Open)
'判断是否为 WebP 文件头
Expand Down
6 changes: 1 addition & 5 deletions Plain Craft Launcher 2/Plain Craft Launcher 2.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@
<Compile Include="Controls\MyIconTextButton.xaml.vb">
<DependentUpon>MyIconTextButton.xaml</DependentUpon>
</Compile>



<Compile Include="Controls\MyImage.vb" />
<Compile Include="Modules\Minecraft\ModComp.vb" />
<Compile Include="Modules\Minecraft\ModJava.vb" />
<Compile Include="Modules\Minecraft\ModMod.vb" />
Expand Down Expand Up @@ -478,7 +476,6 @@
<DependentUpon>FormMain.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>

<Page Include="Modules\Minecraft\MyLocalModItem.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -913,7 +910,6 @@
<Resource Include="Images\Heads\MCBBS.png" />
</ItemGroup>
<ItemGroup>

</ItemGroup>
<ItemGroup>
<Resource Include="Images\Blocks\NeoForge.png" />
Expand Down