안녕하세요. 오랜만에 또 질문을 남기게 됩니다.
bitmapsource 변수 관련한 문제 입니다.
public System.Windows.Media.Imaging.BitmapSource CopyBitmapSource(Bitmap bmp)
{
int dpi = 96;
int width = bmp.Width;
int height = bmp.Height;
PixelFormat format = bmp.PixelFormat;
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, format);
IntPtr ptr = bmpData.Scan0;
bmp.UnlockBits(bmpData);
System.Windows.Media.PixelFormat pf = GetBitmapSourcePixelFormat(format);
int rawStride = (width * pf.BitsPerPixel + 7) / 8;
int bufferSize = bmpData.Stride * bmpData.Height;
System.Windows.Media.Imaging.BitmapSource bitmap = System.Windows.Media.Imaging.BitmapSource.Create(width, height, dpi, dpi, pf, GetBitmapSourcePalette(pf), ptr, bufferSize, rawStride);
return bitmap;
}
위 코드를 실행 후, 메모리가 지속적으로 유지되는 문제가 있습니다.
위 코드로 bitmapsource를 생성, 저장 후 메모리를 회수하고 싶은데 계속 유지가 됩니다.
여러 번 호출 했을 때, 비슷한 크기로 유지되는 것으로 보아 누수 같아 보이지는 않는데 bitmapsource 은 회수를 할 수 없는 것인가요?
bitmapsource 을 사용한 이유는 jpg (8비트) 압축 사용 때문입니다…
혹시 다른 방안이 있는지도 알고싶습니다.
아시는분 있으시면 의견 부탁드립니다.
이상입니다