cancel
Showing results for 
Search instead for 
Did you mean: 

Error when running code stage

EstebanCarrasco
Level 4
I have a code c # to capture the active screen, in debug mode it runs fine but in control room it gives the following problem: Internal: Could not execute code stage due to exception thrown by code stage: Object reference not established as an instance of an object. The code is as follows: System.Windows.Forms.SendKeys.Send ("% {PRTSC}"); Image image = (Image) Clipboard.GetDataObject (). GetData (DataFormats.Bitmap); string extension = ".jpeg"; string path = Output_Directory + Image_Name + "_" + Date_Time + "_" + Product + "_" + System + "_" + Machine_Name + extension; image.Save (path, System.Drawing.Imaging.ImageFormat.Jpeg); Ruta_Screenshot = route; Any idea of the problem?
1 REPLY 1

MikeHiggs
Level 5
Hi, I have success with this... Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height); using (graphics g = Graphics.FromImage (bmpScreenCapture)) { g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0,0, bmpScreenCapture.Size, CopyPixelOperation.SourceCopy); } OutImage = bmpScreenCapture; Output: OutImage Data Type: Image Value: Screenshot you need code options external reference; System.Data.dll System.Xml.dll System.Drawing.dll System.Windows.Forms.dll Namespace Imports System System.Drawing System.Windows.Forms System.Runtime.InteropService Language C# SAVE IMAGE ImageToSave.Save (FilePath); Inputs: ImageToSave Data Type: Image Value: Image to Save Inputs:FilePath Data Type: Text Value: Path