0
我有很多的資源目錄的圖像和訪問他們像這樣...WPF圖像路徑藍調
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我增加了一個功能,調整後的圖像保存到Temp文件夾(即工作),併發送路徑返回 - 但對於一些原因,只是不工作(沒有錯誤,只是沒有圖像)。有任何想法嗎?
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
你看了關於包的URI? http://msdn.microsoft.com/en-us/library/aa970069.aspx – Darlene
有什麼辦法然後將圖像文件保存爲資源? – gchq
爲什麼不直接返回保存圖像的路徑''../../Pages/Temp/「&ImageName'?這就是圖像所在,並且它不會奇蹟般地進入嵌入式資源。 – Clemens