GSDP:GAM100/CProcessing/imageData()
< GSDP:GAM100 | CProcessing
Revision as of 09:56, 24 June 2019 by >Zachary.logsdon
imageData()
Description
Returns the pixel data array of a PImage if it was created with the CP_IMAGE_STORE_PIXEL_DATA set by setImageFlags()
Parameters
imageCreateTint(PImage img)
- img - (PImage) The image to extract the pixel data from.
Example
PImage justin_face;
int x_size, y_size;
void init()
{
setImageFlags(CP_IMAGE_STORE_PIXEL_DATA);
justin_face = loadImage("./Assets/justin1.png");
x_size = imageWidth(justin_face);
y_size = imageHeight(justin_face);
unsigned char* pixel_data = imageData(justin_face);
// Go through and invert the color of the image
unsigned i;
for (i = 0; i < x_size*y_size*4; ++i)
{
if (i % 4 == 3)
continue;
pixel_data[i] = (unsigned char)255 - pixel_data[i];
}
imageUpdate(justin_face);
}
void update()
{
background(color(255, 255, 255, 255));
image(justin_face, canvasWidth/2, canvasHeight/2, x_size, y_size, 255);
}