BmpBitmapDecoder 있지만, 모든 디코더 (GifBitmapDecoder, PngBitmapDecoder, JpegBitmapDecoder, TiffBitmapDecoder)뿐만 아니라 그렇게 당신이 그들을 처분 할 수있는 모든
_myDecoder = null;
GC.Collect();
말 그리고 가비지 컬렉터가 할 수 있도록하는 것입니다, 일회용 클래스 없습니다 그 직업.
BitmapDecoder
의 풀을 만들고 이미지를 FileStream
으로로드하고 이미지의 이진 데이터가 포함 된 이미지를로드 할 수 있습니다. 아래 코드는 당신에게 아이디어를 제공합니다 :
GC.Collect();
// Load the file stream if it hasn't been loaded yet
if (_imageDataStream == null)
_imageDataStream = new FileStream(_imagePath, FileMode.Open, FileAccess.Read, FileShare.Read);
else
_imageDataStream.Seek(0, SeekOrigin.Begin);
string extension = System.IO.Path.GetExtension(_imagePath).ToUpper();
if (extension.Contains("GIF"))
_decoder = new GifBitmapDecoder(_imageDataStream, BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.OnDemand);
else if (extension.Contains("PNG"))
_decoder = new PngBitmapDecoder(_imageDataStream, BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.OnDemand);
else if (extension.Contains("JPG") || extension.Contains("JPEG"))
_decoder = new JpegBitmapDecoder(_imageDataStream, BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.OnDemand);
else if (extension.Contains("BMP"))
_decoder = new BmpBitmapDecoder(_imageDataStream, BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.OnDemand);
else if (extension.Contains("TIF"))
_decoder = new TiffBitmapDecoder(_imageDataStream, BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.OnDemand);
참고로, 귀하는 귀하의 질문에 대한 '동의'및/또는 upvote 정답으로 가정합니다. 이것이 바로 사람들이 StackOverflow에서 "고맙다"고 말하는 방식입니다. – ojrac