Here's my problem:
this method is repeated on a timertick of 50 ms. From the starting of the program to forward in time the RAM memory of this process grows continously and in the end the debugger throws me "out of memory error" to the line that is bolded (drawimage method).
Does anyone can help to me to find a solution to avoid this and explain me why this is happening?
PS. my goal is rotate a background image of a picturebox continously. I know that maybe I could draw directly on form rather than on a pictureBox, but if there is a solution for the pictureBox I will be happy :p
Thanks!
public static Bitmap RotateImage(Image image, PointF offset, float angle)
{
if (image == null)
throw new ArgumentNullException("image");
//create a new empty bitmap to hold rotated image
Bitmap rotatedBmp = new Bitmap(image.Width, image.Height);
rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
//make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(rotatedBmp);
//Put the rotation point in the center of the image
g.TranslateTransform(offset.X, offset.Y);
//rotate the image
g.RotateTransform(angle);
//move the image back
g.TranslateTransform(-offset.X, -offset.Y);
//draw passed in image onto graphics object
**g.DrawImage(image, new PointF(0, 0));**
return rotatedBmp;
}