2013-08-10 3 views
4

웹에서 이미지를 다운로드하여 격리 된 저장소에 저장 했으므로 이제 XAML 파일에서 해당 이미지에 액세스하여 Uri를 그들에 대한 참조."isostore : /"체계를 사용하여 XAML의 격리 된 저장소에서 이미지에 액세스

IsoStoreSpy를 사용하여 예상 한 위치에 올바르게 저장되어 있는지 확인하고 파일을 열고 바이트 스트림에서 읽을 경우 BitmapImages를 만들 수 있습니다. 하지만 이제는 모델에서 IsolatedStorage 위치로 Uri를 전달하고 내 XAML에 이미지로드를 허용하여 이미지 처리를 최적화하려고합니다.

"isostore : /PodcastIcons/258393889fa6a0a0db7034c30a8d1c3322df55696137611554288265.jpg"여기

내가 그것을 구성했습니다 어떻게

<Image Height="120" Width="120" Stretch="Uniform" HorizontalAlignment="Left"> 
    <Image.Source> 
    <BitmapImage UriSource="{Binding PodcastLogoUri}" DecodePixelHeight="120" DecodePixelWidth="120" /> 
    </Image.Source> 
</Image> 

는 BitmapImage.UriSource에 바인딩 된 PodcastLogoUri 열린 우리당 값입니다 :

public Uri PodcastLogoUri 
{ 
    get 
    { 

     Uri uri = new Uri(@"isostore:/" + PodcastLogoLocation); 
     return uri; 
    } 
} 

그래도 UI에서 이미지를 볼 수 없습니다. 그리고 이미지가 PodcastLogoLocation에 있다고 확신합니다.

Windows Phone 8과 같이 격리 된 저장소에서 이미지를 UI로 참조 할 수 있습니까? 내가 도대체 ​​뭘 잘못하고있는 겁니까?

편집 : 나는 BitmapImage 직접 같은 경로를 사용하고 XAML에서 BitmapImage를 사용하여 작성하는 경우, 그것을 잘 작동하고 나는 내가 거기에 볼 것으로 예상 이미지를 볼 수 있습니다 :

<Image Height="120" Source="{Binding PodcastLogo}" Width="120" Stretch="Uniform" HorizontalAlignment="Left"/> 
public BitmapImage PodcastLogo 
{ 
    get 
    { 
      Stream stream = null; 
      BitmapImage logo = new BitmapImage(); 
      using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) 
      { 
       if (isoStore.FileExists(PodcastLogoLocation)) 
       { 
       stream = isoStore.OpenFile(PodcastLogoLocation, System.IO.FileMode.Open, FileAccess.Read); 
       try 
       { 
         logo.SetSource(stream); 
       } 
       catch (Exception e) 
       { 
       } 

      } 
     } 

     return logo; 
    } 
} 
+0

그것은'UriKind.Absolute'없이 시도한다? –

+0

제안 해 주셔서 감사합니다. 그러나 도움이되지 않았습니다. :-( –

+0

어쩌면 내 질문은 내가 기대했던 것처럼 곧장 나아지지 않을 수도있다. 나는 또한 MSDN 포럼에 게시했으며, 그것에 대한 답변을 얻지 못했다. 나는 정말로 그저 내가 grokking하지 않는다고 생각했다. 누군가 나를 그렇게 빨리 지적 해주었습니다. 그렇지 않습니다. http://social.msdn.microsoft.com/Forums/wpapps/en-US/0c1948a7-d4fc-4aa3-b30d-97213a7a816f/accessing-images-from-isolated- storage-in-xaml-is-isostore-scheme # 0c1948a7-d4fc-4aa3-b30d-97213a7a816f –

답변

5

나는 당신이하려고하는 것과 똑같은 것을했다고 생각합니다. 내가 찾은 것은 격리 된 저장소가 IsolatedStorageFile.GetUserStoreForApplication()을 사용하여 파일을 저장하는 절대 위치입니다. 이것은 "C:/Data/Users/DefApps/AppData/<App Product ID>/Local/<YourFile.png>"과 같습니다. 나는 윈도우 폰 8이 해결 방법을 테스트 한 그리고 그것은 나를 위해 작동

...

1. XAML

<Image Width="40"> 
    <Image.Source> 
     <BitmapImage DecodePixelWidth="40" DecodePixelHeight="40" UriSource="{Binding Path=Icon}" /> 
    </Image.Source> 
</Image> 

2.뷰 모델

private string _icon; 
public string Icon 
{ 
    get 
    { 
     return _icon; 
    } 
    set 
    { 
     if (value != _icon) 
     { 
      _icon = value; 
      NotifyPropertyChanged("Icon"); 
     } 
    } 
} 

3. 데이터로드

filename = "Myicon.png"; 

IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); 
if (!store.FileExists(filename)) 
{ 
    using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filename, FileMode.Create, FileAccess.Write, store)) 
     stream.Write(imgBytes, 0, imgBytes.Length); 
} 

//get Product ID from manifest. Add using System.Linq; if you haven't already 
Guid productId = new Guid((from manifest in System.Xml.Linq.XElement.Load("WMAppManifest.xml").Descendants("App") select manifest).SingleOrDefault().Attribute("ProductID").Value); 
string storeFile = "C:/Data/Users/DefApps/AppData/" + productId.ToString("B") + "/Local/" + filename; 

this.Items.Add(new MyViewModel() { Icon = storeFile }); 
2

을 슬프게도 이것은 결국 불가능한 것 같습니다. 나는 약간 충격을 받았고 이것으로 인해 많은 실망감을 느꼈다. MS가이 사건을 어떻게 지원하지 않는지 정말로 이해할 수 없습니다. 그것은 XAML은 ISOStore URI 구성표와 격리 된 저장소에서 직접 바인딩 지원되지 않음

:

이것은 내가 MSDN 포럼에 이상 가지고 대답이다.

다음은 답변에 대한 답변입니다.

http://mark.mymonster.nl/2013/05/24/yeah-windows-phone-supports-isolated-storage-access-through-an-uri-scheme-does-it

그래서 그것 뿐이다.