Hi,
I've written the code below in order to take numbers of images from desktop to make a video with images, it works, but CPU usage is about 80 or 90%. I tried to make it use lower CPU but I couldn't. Is there a way to optimize the code to not use that much of CPU?
My CPU is intel dual core 2200
Please help.
private int num;
private void timer1_Tick(object sender, EventArgs e)
{
SendKeys.Send("{PRTSC}");
Image i = Clipboard.GetImage();
i.Save("pics\\" + num, System.Drawing.Imaging.ImageFormat.Png);
num++;
}
I'v used code below with 100 as timer interval but cpu usage gets over 90% :
int ScreenWidth = Screen.PrimaryScreen.Bounds.Width;
int ScreenHeight = Screen.PrimaryScreen.Bounds.Height;
Graphics g;
Bitmap b = new Bitmap(ScreenWidth, ScreenHeight);
g = Graphics.FromImage(b);
g.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);
b.Save("pics//" + num++);
this is another code that uses 20% of the cpu , its okay,its memory usage is around 20 mb but after 1minute and suddenly it goes over 1.5 GB!!! why is that??!!
code :
Int64 num;
Bitmap[] bit = new Bitmap[200000000];
int ScreenWidth = Screen.PrimaryScreen.Bounds.Width;
int ScreenHeight = Screen.PrimaryScreen.Bounds.Height;
Graphics g;
Bitmap b = new Bitmap(ScreenWidth, ScreenHeight);
g = Graphics.FromImage(b);
g.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);
bit[num++] = b;
Thanks