Code is here :
public Bitmap ScreenCaptureBitmap(int DesktopX, int DesktopY, int CaptureWidth, int CaptureHeight)
{
Bitmap ScreenCaptureBmp = new Bitmap(CaptureWidth, CaptureHeight);
Graphics graphics = Graphics.FromImage(ScreenCaptureBmp as Image);
graphics.CopyFromScreen(DesktopX, DesktopY, 0, 0, ScreenCaptureBmp.Size);
graphics.Dispose();
return ScreenCaptureBmp;
}
public Bitmap ResizeBitmap(Bitmap ResizeBmp, int RBmpWidth, int RBmpHeight)
{
Bitmap RBmp = new Bitmap(RBmpWidth, RBmpHeight);
using (Graphics RBmpG = Graphics.FromImage((Image)RBmp))
RBmpG.DrawImage(ResizeBmp, 0, 0, RBmpWidth, RBmpHeight);
return RBmp;
}
private void timer1_Tick(object sender, EventArgs e)
{
Bitmap Pic = ScreenCaptureBitmap(50, 50, 640, 320);
Bitmap Pic1 = ResizeBitmap(Pic, 128, 64);
pictureBox1.Image = Pic1;
}
Which Bitmap I have to dispose? (I don't know if I have to dispose all of these "ScreenCaptureBmp", "ResizeBmp", "RBmp", "Pic", "Pic1" or Some of these).
Did I have to dispose return Bitmap of a method? (Example: "ScreenCaptureBmp", "RBmp").
Did I dispose Graphics("graphics", "RBmpG") in right way in this code?
WHERE I HAVE TO WRITE DISPOSE TO DISPOSE IN RIGHT WAY?
If I write this code:
public Bitmap ScreenCaptureBitmap(int DesktopX, int DesktopY, int CaptureWidth, int CaptureHeight)
{
Bitmap ScreenCaptureBmp = new Bitmap(CaptureWidth, CaptureHeight);
using (Graphics graphics = Graphics.FromImage(ScreenCaptureBmp as Image))
graphics.CopyFromScreen(DesktopX, DesktopY, 0, 0, ScreenCaptureBmp.Size);
return ScreenCaptureBmp;
}
public Bitmap ResizeBitmap(Bitmap ResizeBmp, int RBmpWidth, int RBmpHeight)
{
Bitmap RBmp = new Bitmap(RBmpWidth, RBmpHeight);
using (Graphics RBmpG = Graphics.FromImage((Image)RBmp))
RBmpG.DrawImage(ResizeBmp, 0, 0, RBmpWidth, RBmpHeight);
return RBmp;
}
private void timer1_Tick(object sender, EventArgs e)
{
Bitmap Pic = ScreenCaptureBitmap(50, 50, 640, 320);
Bitmap Pic1 = ResizeBitmap(Pic, 128, 64);
Pic.Dispose();
using (Image PreviewImage = pictureBox1.Image)
{
pictureBox1.Image = Pic1;
}
}
Does everything dispose in correct way in this(2nd) code?
Is disposing in "timer1_Tick" method correct in this(2nd) code?