Hi, guys, I'm programming some artificial intelligence for a graphics program, Graphics Gale. The program is horrible, it won't let me combine layers with the same name, and it won't let me save the image as a Photoshop file, so what do I have to do? I have to code some AI. I have around 260 images that i need the layers combined, so I got all the AI working except for one part that makes no sence what so ever. It copies the current layer's image to the clipboard, and then saves it to a specified folder, but I cannot get the clipboard copying to work. I do the SendKeys function to copy the image to the clipboard, then make an image variable with the clipboard image( Clipboard.GetImage() ). It sometimes says it can't open the clipboard, and then other times it says it has a image, but it's null, then othertimes the variable shows my previous clipboard. Anyways, here's my code for getting the image.
//SendKeys with sleep just incase the thing wasn't working because it was too fast.
public void SendText(string text)
{
System.Threading.Thread.Sleep(150);
SendKeys.Send(text);
}
public void GetImage()
{
//clears the clipboard, because many times it would set it to my old clipboard image
Clipboard.Clear();
//makes sure the program's canvas is selected, then copies the image via cut and paste
SendText("{ESC}");
SendText("^a");
SendText("^x");
//the code that doesn't work.
pictureBox1.Image = Clipboard.GetImage();
}
private void timer1_Tick(object sender, EventArgs e)
{
//if i press the middle mouse button, then it calls the AI function.
if (GetAsyncKeyState(4) == -32767)
GetImage();
}