zip 파일에서 직접 이미지 소스를로드하는 방법은 무엇입니까?Wpf : 파일을 저장하지 않고 zip에서 이미지 소스로드
나는 DotNetZip을 사용합니다.
아래 2 코드 샘플.
코드 샘플 1은 이미지 파일을로드하고 표시하지 못합니다.
코드 샘플 1 MemoryStream에 zipEntry를로드하고 Imagesource로 사용할 BitmapImage를 만들지 만 실패합니다. ??? 테스트 용으로 memorystream에서 이미지를 저장하려고 시도하여 Zip 항목이로드되었는지 확인합니다. 제대로 저장됩니다
이 MemoryStream memoryStream1 = new MemoryStream();
ZipFile zip = ZipFile.Read(@"D:\myZipArcive.zip");
ZipEntry myEntry = zip["myfile.jpg"];
myEntry.Extract(memoryStream1);
memoryStream1.Close();
System.IO.File.WriteAllBytes(@"D:\saved.jpg", memoryStream1.ToArray());
//save file just for testing
BitmapImage src = new BitmapImage();
src.BeginInit();
src.CacheOption = BitmapCacheOption.OnLoad;
src.StreamSource = memoryStream1;
src.EndInit();
myImage.Source = src as ImageSource; //no image is displayed
내가 MemoryStream을에 파일을로드하고 BitmapImage를 생성이 코드 샘플은 succes에 함께 Imagesource로 사용할 수 있습니다. "형 'System.NotSupportedException'형식의 첫째 예외가가 mscorlib.dll에서 발생했습니다"
: 내가 디버그 메시지가 1 샘플에서 MemoryStream을, 내가 실행 예제 1에 문제가 있습니다 FileStream fileStream = File.OpenRead(@"D:\myFile.jpg");
MemoryStream memoryStream2 = new MemoryStream();
memoryStream2.SetLength(fileStream.Length);
fileStream.Read(memoryStream2.GetBuffer(), 0, (int)fileStream.Length);
BitmapImage src = new BitmapImage();
src.BeginInit();
src.CacheOption = BitmapCacheOption.OnLoad;
src.StreamSource = memoryStream2;
src.EndInit();
myImage.Source = src as ImageSource; //The image is displayed
헤이 클레멘스 감사합니다. 그것은 위대한 작품! –
@ErikT 내 업데이트를 참조하십시오. 아마 그것은 조금 더 잘 수행됩니다. – Clemens