2011-08-25 3 views
2

jpg 파일을 읽고 laterer를 Image 컨트롤에 표시해야합니다. 완벽하게 다음 작품 :WPF - Byte []에서 JpegBitmapDecoder를 사용하여 BitmapSource로 파일 변환

imgTwo.Source = FetchImage(@"C:\Image075.jpg"); 

public BitmapSource FetchImage(string URLlink) 
{ 
     JpegBitmapDecoder decoder = null; 
     BitmapSource bitmapSource = null; 
     decoder = new JpegBitmapDecoder(new Uri(URLlink, UriKind.Absolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); 
     bitmapSource = decoder.Frames[0]; 
     bitmapSource.Freeze(); 
     return bitmapSource; 
} 

내 문제는 내가 위에서처럼 파일에서 직접적으로, 바이트 [] (VARBINARY (MAX와 같은 데이터베이스에이 이미지를 유지)하고 거기에서 읽을 필요가있다 . 그래서 나는 바이트를 가지고 하나 필요 []이 기능을 대신 URLlink 문자열, 또는에 대한 입력으로 바이트 []를. 내가 어떻게 그?

답변

4

JpegBitmapDecoderStream 받아들이는 second constructor을 가지고로 BitmapSource는 저장 . 이 포함 된 MemoryStream을 전달하십시오 :

using(var stream = new MemoryStream(yourByteArray)) 
{ 
    decoder = new JpegBitmapDecoder(stream, 
            BitmapCreateOptions.PreservePixelFormat, 
            BitmapCacheOption.OnLoad); 
} 
+0

Det가 제대로 작동했습니다. 당신의 도움을 주셔서 대단히 감사합니다. :-) – Keren

관련 문제