Ok, in my project resources i have some images (.png). Whenever the user clicks on a Button
a new image will be shown in an ImageBox
. Because all of my images are stored in my project resources i have to get the Image.Source
by code. I managed to do it by using a Method
like this :
public void ImageSource()
{
Bitmap someImage;
BitmapSource someImageSource;
someImage= new Bitmap(Properties.Resources.Image1);
someImageSource = getBitmapSourceFromBitmap(someImage);
ImageBox.Source = someImageSource;
}
public static BitmapSource getBitmapSourceFromBitmap(Bitmap bmp)
{
BitmapSource returnSource = null;
try
{
returnSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
catch { returnSource = null; }
return returnSource;
}
In my app everything works fine. No errors , no warnings, images change fine every time i push the Button
. After some monitoring in the memory , i noticed that every time i call the getBitmapSourceFromBitmap
my memory explodes 100MB EVERY TIME.
Does anyone have any idea why is this happening?
Sorry for my English.