0

我在资源目录中有许多图像并像这样访问它们......

Public Function ReturnToolBarImage(ByVal ImageName As String) As Image
    Dim UpdateImage As New Image
    With UpdateImage
    End With
    Dim UpdateBitmap As New BitmapImage
    With UpdateBitmap
        .BeginInit()
        .UriSource = New Uri("pack://application:,,,/HOA_Manager_Client_04;component/Resources/" & ImageName, UriKind.Absolute)
        .EndInit()
        .DecodePixelHeight = 32
    End With
    UpdateImage.Source = UpdateBitmap
    Return UpdateImage
End Function

我有控制权坚持使用图像路径而不是图像 - 我可以像这样访问它

.ImageSource = "//application:,,,/HOA_Manager_Client_04;component/Resources/Customers.png"

但是图像,或者当然,太大了.. Soooooo 我添加了一个功能来将调整大小的图像保存到临时文件夹(正在工作)并将路径发回 - 但由于某种原因,它不起作用(不错误,只是没有图像)。有任何想法吗?

Public Function ReturnToolBarImageAsString(ByVal ImageName As String) As String
    Dim UpdateImage As New Image
    With UpdateImage
    End With
    Dim UpdateBitmap As New BitmapImage
    With UpdateBitmap
        .BeginInit()
        .UriSource = New Uri("pack://application:,,,/HOA_Manager_Client_04;component/Resources/" & ImageName, UriKind.Absolute)
        .EndInit()
        .DecodePixelHeight = 32
    End With
    Using FS As New IO.FileStream("../../Pages/Temp/" & ImageName, IO.FileMode.Create)
        Dim vEncoder As New PngBitmapEncoder
        vEncoder.Frames.Add(BitmapFrame.Create(UpdateBitmap))
        vEncoder.Save(FS)
    End Using
    'Return "../Temp/" & ImageName
    Return "//application:,,,/HOA_Manager_Client_04;component/Pages/Temp/" & ImageName
End Function
4

1 回答 1

0

通过在运行时在 Bi​​n 目录中创建一个目录似乎已经解决了这个问题

Public Function ReturnToolBarImageAsString(ByVal ImageName As String) As String
    Dim UpdateImage As New Image
    With UpdateImage
    End With
    Dim UpdateBitmap As New BitmapImage
    With UpdateBitmap
        .BeginInit()
        .DecodePixelHeight = 32
        .UriSource = New Uri("pack://application:,,,/HOA_Manager_Client_04;component/Resources/" & ImageName, UriKind.Absolute)
        .EndInit()
    End With

    Dim vPath As String = My.Application.Info.DirectoryPath
    If Not IO.Directory.Exists(vPath & "\Temp_Images") Then
        IO.Directory.CreateDirectory(vPath & "\Temp_Images")
    End If
    Using FS As New IO.FileStream(vPath & "\Temp_Images\" & ImageName, IO.FileMode.Create)
        Dim vEncoder As New PngBitmapEncoder
        vEncoder.Frames.Add(BitmapFrame.Create(UpdateBitmap))
        vEncoder.Save(FS)
    End Using
    Return vPath & "\Temp_Images\" & ImageName
End Function
于 2013-06-22T11:49:08.957 回答