feat: 修改实现方式
This commit is contained in:
+18
-16
@@ -1,32 +1,34 @@
|
|||||||
Public Class MyImage
|
Public Class MyImage
|
||||||
|
Inherits Image
|
||||||
|
|
||||||
|
'事件
|
||||||
|
|
||||||
'自定义属性
|
|
||||||
Public Uuid As Integer = GetUuid()
|
Public Uuid As Integer = GetUuid()
|
||||||
Private _Uri As String = ""
|
|
||||||
|
|
||||||
Public Property Source As String
|
Private _SourceData As String = ""
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' 重写Image的Source属性
|
||||||
|
''' </summary>
|
||||||
|
Public Shadows Property Source As String
|
||||||
Get
|
Get
|
||||||
Return _Uri
|
Return _SourceData
|
||||||
End Get
|
End Get
|
||||||
Set(value As String)
|
Set(value As String)
|
||||||
_Uri = value
|
SetImage(value)
|
||||||
RefreshImage()
|
|
||||||
End Set
|
End Set
|
||||||
End Property '显示文本
|
End Property
|
||||||
Public Shared ReadOnly SourceProperty As DependencyProperty = DependencyProperty.Register("Source", GetType(String), GetType(MyImage), New PropertyMetadata(New PropertyChangedCallback(
|
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)
|
Sub(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
|
||||||
If Not IsNothing(sender) Then
|
If Not IsNothing(sender) Then
|
||||||
CType(sender, MyImage)._Uri = e.NewValue.ToString()
|
CType(sender, MyImage).SetImage(e.NewValue)
|
||||||
CType(sender, MyImage).RefreshImage()
|
|
||||||
End If
|
End If
|
||||||
End Sub)))
|
End Sub)))
|
||||||
|
|
||||||
Public Sub RefreshImage()
|
Private Sub SetImage(source As String)
|
||||||
If Me Is Nothing Then Exit Sub
|
If Me Is Nothing Then Exit Sub
|
||||||
Try
|
If String.IsNullOrEmpty(source) Then Exit Sub
|
||||||
PanContent.Source = New MyBitmap(_Uri.ToString())
|
_SourceData = source
|
||||||
Catch ex As Exception
|
MyBase.Source = New MyBitmap(_SourceData)
|
||||||
Log(ex, "刷新图片内容失败")
|
|
||||||
End Try
|
|
||||||
End Sub
|
End Sub
|
||||||
End Class
|
End Class
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
<Border x:Class="MyImage"
|
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
FocusVisualStyle="{x:Null}" x:Name="PanBack"
|
|
||||||
ClipToBounds="True" UseLayoutRounding="False" SnapsToDevicePixels="False" Background="{StaticResource ColorBrushSemiTransparent}">
|
|
||||||
<Image x:Name="PanContent"/>
|
|
||||||
</Border>
|
|
||||||
@@ -64,10 +64,17 @@ Public Class MyBitmap
|
|||||||
BitmapCache.Add(FilePathOrResourceName, Pic)
|
BitmapCache.Add(FilePathOrResourceName, Pic)
|
||||||
End If
|
End If
|
||||||
Else
|
Else
|
||||||
|
If FilePathOrResourceName.StartsWithF("http") Then '在线图片(这里判断 https:\\ 或 http:\\ 会出问题)
|
||||||
Dim tempFile = PathTemp & "Cache\MyImage\" & GetHash(FilePathOrResourceName)
|
Dim tempFile = PathTemp & "Cache\MyImage\" & GetHash(FilePathOrResourceName)
|
||||||
If FilePathOrResourceName.StartsWith("http") Then
|
|
||||||
NetDownload(FilePathOrResourceName, tempFile, True)
|
NetDownload(FilePathOrResourceName, tempFile, True)
|
||||||
FilePathOrResourceName = tempFile
|
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
|
End If
|
||||||
'使用这种自己接管 FileStream 的方法加载才能解除文件占用
|
'使用这种自己接管 FileStream 的方法加载才能解除文件占用
|
||||||
Using InputStream As New FileStream(FilePathOrResourceName, FileMode.Open)
|
Using InputStream As New FileStream(FilePathOrResourceName, FileMode.Open)
|
||||||
|
|||||||
@@ -183,9 +183,6 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
<Compile Include="Controls\IMyRadio.vb" />
|
<Compile Include="Controls\IMyRadio.vb" />
|
||||||
<Compile Include="Controls\MyImage.xaml.vb">
|
|
||||||
<DependentUpon>MyImage.xaml</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Controls\MyComboBox.vb" />
|
<Compile Include="Controls\MyComboBox.vb" />
|
||||||
<Compile Include="Controls\MyComboBoxItem.vb" />
|
<Compile Include="Controls\MyComboBoxItem.vb" />
|
||||||
<Compile Include="Controls\MyCard.vb" />
|
<Compile Include="Controls\MyCard.vb" />
|
||||||
@@ -194,6 +191,7 @@
|
|||||||
<Compile Include="Controls\MyIconTextButton.xaml.vb">
|
<Compile Include="Controls\MyIconTextButton.xaml.vb">
|
||||||
<DependentUpon>MyIconTextButton.xaml</DependentUpon>
|
<DependentUpon>MyIconTextButton.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Controls\MyImage.vb" />
|
||||||
<Compile Include="Modules\Minecraft\ModComp.vb" />
|
<Compile Include="Modules\Minecraft\ModComp.vb" />
|
||||||
<Compile Include="Modules\Minecraft\ModJava.vb" />
|
<Compile Include="Modules\Minecraft\ModJava.vb" />
|
||||||
<Compile Include="Modules\Minecraft\ModMod.vb" />
|
<Compile Include="Modules\Minecraft\ModMod.vb" />
|
||||||
@@ -381,10 +379,6 @@
|
|||||||
<Compile Include="Pages\PageSpeedRight.xaml.vb">
|
<Compile Include="Pages\PageSpeedRight.xaml.vb">
|
||||||
<DependentUpon>PageSpeedRight.xaml</DependentUpon>
|
<DependentUpon>PageSpeedRight.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Page Include="Controls\MyImage.xaml">
|
|
||||||
<Generator>MSBuild:Compile</Generator>
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
</Page>
|
|
||||||
<Page Include="Controls\MyExtraButton.xaml">
|
<Page Include="Controls\MyExtraButton.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
|||||||
Reference in New Issue
Block a user