0 votes
535 views
by (150 points)

Hi!
I'm generating stimulus with 256 black and white squares (40x40px) - So 16 squares per row

I added a GDI Canvas (640x640) and a roulette and add this to 'beforeonset'


int row=0;
int col=0;
for (int i=0;i<256;i++)
{
	if (block[i]==1){ //block roulette
		GraphicsClass.FillRectangle(new SolidBrush(Color.White), (col*40),(row*40),(col*40)+40,(row*40)+40);		
	}else{
			GraphicsClass.FillRectangle(new SolidBrush(Color.Black), (col*40),(row*40),(col*40)+40,(row*40)+40);		
	}
	if (col==16){
		col=0;
		row++;	
	}else{
		row++;
	}
}

------

then I added 

ResetBlockNow=true;

in Before Offset 

Now I want to save to a JPG file each stimulus that I generate in graphics class.

Can anyone help me ?

Thanks!

1 Answer

0 votes
by (14.5k points)
selected by
 
Best answer

Hi!

There is no an easy way to save the generated canvas image to a file directly. In theory the Graphics class in GDI+ allows copying graphics to a bitmap, which, in turn, can be saved into a file. In practice, however, it did not work last time I tried it.

There is another easy way to save a screenshot of the entire screen (at any runtime moment) with a dedicated command. In order to do it:

  1. Go to the Experiment ribbon tab.
  2. In the Properties panel find the 'Save Screenshot Now' property and create a proxy variable bound to it.
  3. Use the following code in a snippet that is invoked right after the updated canvas is rendered on the screen:

 

SaveScreenshotNow=@"C:\MyData\Stimuli_"+StimulusNumber+".jpg"; /* StimulusNumber represents some stimulus id.*/

 

A couple of remarks on the above procedure:

You should not use SaveScreenshotNow in the same snippet, in which GraphicsClass does rendering procedures. Instead, you have to wait until the new rendering is presented on the screen, which typically happens automatically after the 'rendering' snippet call. Thus, the best place for the SaveScreenshotNow command is the next snippet in a timeline, given that the target event (one containing the GDI Canvas element) is active. If you do rendering in advance, then wait until the onset of the target event to make a screenshot.

In the newest version of EventIDE, you need to apply rendering updates on the GDI Canvas Element manually, by calling 'UpdateCanvasNow=true;', right after the rendering procedures. The 'Update Canvas Now' is a new command property of the GDI canvas element.

I hope you find the above useful. Please contact me directly, if you need more details or any help.

 

 

 

 

 

 

 

Welcome to EventIDE Q&A forum where you can ask questions about EventIDE software and receive answers from other members of the community

Categories

FAQ questions

Installation and License


Coding


Eye-tracking


EEG Analysis


Visual Stimuli


Runtime and Data Collection


Hardware

...