2011-02-09 5 views
1

BLOB 저장소의 클라우드에 PNG 파일이 저장되어 있으므로 다운로드하고 WPF의 화면에 렌더링하고 싶습니다.WPF BitmapFrame 및 다중 스레드

Dispatcher 및 Freezing에 대해 알고 있지만 아무 것도 작동하지 않습니다. "다른 스레드가 소유하고있다"라는 오류가 계속 발생합니다. 여기

내가 무엇을 가지고 :

var decoder = GetDecoder("http://address/image.png"); 

Dispatcher.Invoke(DispatcherPriority.Send, new Action<BitmapFrame>(SetImage), decoder.Frames[0]); 

public void SetImage(BitmapFrame source) 
{ 
    var bitmapFrame = BitmapFrame.Create(source); //ERROR HERE!!!!!!!! 
    LazyImage.Source = bitmapFrame; 
} 

private BitmapDecoder GetDecoder(object uri) 
{ 
    var extension = System.IO.Path.GetExtension((string)uri); 
    BitmapDecoder decoder = null; 
    if (extension.ToLower() == ".png") 
     decoder = BitmapDecoder.Create(new Uri((string)uri, UriKind.Absolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); 
    return decoder; 
} 

내가 [0] 나는이 프레임이 고정 될 수 없다는 예외가 프레임을 동결하려고하면

. 또한 BitmapDecoder.Create에 의해 반환 된 디코더는 이 아니며PngBitmapDecoder이 아니지만 실제로 사용하는 방법을 잘 모르는 LateBoundBitmapDecoder입니다.

답변

1

Dispatcher뿐만 아니라 BitmapDecoder에서도 Bitmapframe을 만들 필요가있을 가능성이 있습니까? Dispatcher에서 GetDecoder를 호출 해 보았습니까?

+0

아마도, I는 디코더의 창조가 I는 UI 스레드에서 발생 방지하고자하는 것을 의미 동기 동작 생각한다. Decoder가'PngBitmapDecoder'이므로 내 로컬 PC의 파일 (http URL이 아닌)이 그대로 작동합니다. – Mark

+0

음 ... 아마도 스레드에서 BitmapFrame.Create()를 호출하여 반환하는 프레임을 고정하려면? – Lugoues

+0

LateBoundBitmapDecoder에서 반환 한 프레임을 고정하면 예외가 발생하지만 로컬 URL (따라서 PngBitmapDecoder)을 사용하면 고정시킬 수 있습니다. – Mark

1

간략한 설명 : 결과를 WriteableBitmap에 넣어보십시오.

Long story, with code.

+0

제 경우에는 이것이 유일한 해결책이었습니다. TransformedBitmap에 BitmapFrame을 공급해야했습니다. BitmapFrame이 라이브러리에 의해 제공되었으므로 (그리고 BitmapFrame의 Dispatcher 속성이 null 임) BitmapFrame이 생성 된 스레드를 제어 할 수 없었습니다. CanFreeze 속성을 쿼리해도 예외가 발생했습니다. 두 가지 옵션이 있습니다 : 광산 및 기타 소스 코드의 대대적 인 정비 또는 WriteableBitmap 사용. 내가 선택한 건 ... – elgonzo