This article applies to:
This sample demonstrates the use of the Canvas.GetPixel method to identify colors in an image in order to determine which part of an image is clicked.
This sample uses multiple off-screen canvases. It is also important to know the dimensions of the images being used if they are not the same resolution that the experiment is run at. If the image dimensions are smaller than the resolution used at runtime, Inline script is used to define where the image should appear. The images are then copied to a new off-screen canvas using the Source and Destination parameters in the Canvas.Copy method.
A segmented color wheel image is loaded and centered to an off-screen canvas. Each pedal of the wheel has a color filled in. This image remains on the off-screen so that the GetPixel method can identify which color the cursor is over, no matter what is actually presented on screen.
Other off-screen canvases are created to hold individual images; ones that show each pedal of the color wheel filled in individually as well as a blank wheel.
Once each off-screen canvas is created, the one containing the blank wheel is copied and drawn to the screen while the colored wheel is drawn off-screen in the same location. Mouse tracking is used in Inline script to identify where the cursor is on screen. The mouse tracking occurs in a Do While...Loop in script. Also in this Loop, the GetPixel method is used to identify the color of the pixel on the off-screen that the cursor is currently over. The color ID is then converted to an RGB value.
While hovering and actively identifying which color pixel the cursor is over on the off-screen canvas, depending on the color, copies the respective individual pedal image of the identified color to the on-screen canvas. This simulates that each pedal presents its color when hovered over with the cursor.
Participants are prompted to click a certain color on the color wheel, which can be identified by hovering over the different pedals with the cursor. Once a response is made, the RGB color value that was clicked is compared to the RGBColor Attribute in TrialList to judge accuracy on a per trial basis.