GSDP:GAM100/CProcessing/imageCreateSubimageAdvanced()

From Inside
Jump to: navigation, search

imageCreateSubimageAdvanced()

Description

Returns a PImage that is a copied section of a another PImage. Must have used one of the advanced image functions and set the copyPixelData bool to true. Using imageCreateSubimageAdvanced() lets you set a few flags that are described below.

Parameters

imageCreateSubimage(PImage srcImg, float x, float y, float w, float h, bool copyPixelData, bool usePixelPerfectFiltering)

  • img - (PImage) The source image to copy of section of.
  • x - (int) The x coordinate of which pixel to start the sub-image from.
  • y - (int) The y coordinate of which pixel to start the sub-image from.
  • w - (int) The width of the sub-image in pixels
  • h - (int) The height of the sub-image in pixels
  • copyPixelData - (bool) Copies the pixel data of the image so it can be manipulated later
  • usePixelPerfectFiltering - (bool) Turns off bilinear smoothing for images, good for pixel art

Example

PImage whole;
PImage sub[4];
PImage subTinted[4];
int x_size, y_size;

void init()
{
  whole = loadImageAdvanced("./Assets/justin1.png", true, false);

  x_size = imageWidth(whole);
  y_size = imageHeight(whole);

  // Create the sub image quarters
  sub[0] = imageCreateSubimageAdvanced(whole, 0, 0, x_size / 2, y_size / 2, true, false);
  sub[1] = imageCreateSubimageAdvanced(whole, x_size / 2, 0, x_size / 2, y_size / 2, true, false);
  sub[2] = imageCreateSubimageAdvanced(whole, 0, y_size / 2, x_size / 2, y_size / 2, true, false);
  sub[3] = imageCreateSubimageAdvanced(whole, x_size / 2, y_size / 2, x_size / 2, y_size / 2, true, false);

  // Create the tinted images based on the sub images
  subTinted[0] = imageCreateTint(sub[0], color(255, 0, 0, 255));
  subTinted[1] = imageCreateTint(sub[1], color(255, 255, 0, 255));
  subTinted[2] = imageCreateTint(sub[2], color(0, 255, 0, 255));
  subTinted[3] = imageCreateTint(sub[3], color(0, 0, 255, 255));
}

void update()
{
  background(color(255, 255, 255, 255));

  // Draws the image with each quarter tinted a different color
  image(subTinted[0], mouseX - (float)x_size / 2.0f, mouseY - (float)y_size / 2.0f, (float)x_size / 2.0f, (float)y_size / 2.0f, 255);
  image(subTinted[1], mouseX, mouseY - (float)y_size / 2.0f, (float)x_size / 2.0f, (float)y_size / 2.0f, 255);
  image(subTinted[2], mouseX - (float)x_size / 2.0f, mouseY, (float)x_size / 2.0f, (float)y_size / 2.0f, 255);
  image(subTinted[3], mouseX, mouseY, (float)x_size / 2.0f, (float)y_size / 2.0f, 255);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>