Graphics::drawImage

Description

void Graphics::drawImage( int16_t x , int16_t y , Image img [, int16_t w2 , int16_t h2 ] )
void Graphics::drawImage( int16_t x , int16_t y , Image img , int16_t source_x , int16_t source_y , int16_t source_width , int16_t source_height )

Graphics::drawImage draws an image to the display/light/other image etc. If the image is animated it automatically progresses the animation, based on the set parameters. You can also re-scale or crop the image if you want to.

Keep in mind that you cannot draw full-color images onto indexed images!

Read the Image tutorial.

Parameters

  • int16_t x: x-coordinate where to draw the image
  • int16_t y: y-coordinate where to draw the image
  • Image img: the image to draw
  • int16_t w2 (optional): new width (for scaling)
  • int16_t h2 (optional): new height (for scaling)
TRICK : you can use negative values for w2 and/or h2 to flip image horizonttally or vertically

With source parameters:

  • int16_t source_x: x-coordinate in source image where to begin drawing
  • int16_t source_y: y-coordinate in source image where to begin drawing
  • int16_t source_width: width in source image to what to crop to
  • int16_t source_height: height in source image to what to crop to

Returns

none

Example

#include <Gamebuino-Meta.h>

// create red-yellow checkerboard image const uint8_t imgBuffer[] = { 8, 8, 1, 0, 0, 0xFF, 1, 0x6A, 0x6A, 0x6A, 0x6A, 0xA6, 0xA6, 0xA6, 0xA6, 0x6A, 0x6A, 0x6A, 0x6A, 0xA6, 0xA6, 0xA6, 0xA6, 0x6A, 0x6A, 0x6A, 0x6A, 0xA6, 0xA6, 0xA6, 0xA6, 0x6A, 0x6A, 0x6A, 0x6A, 0xA6, 0xA6, 0xA6, 0xA6, }; Image img(imgBuffer);

void setup() { gb.begin(); }

void loop() { while(!gb.update()); gb.display.clear();

// draw the image onto the screen gb.display.drawImage(0, 0, img);

// and now draw and upscale at the same time gb.display.drawImage(8, 0, img, img.width()*2, img.height()*2);

// and now only draw the middle 4x4 part of the image gb.display.drawImage(24, 0, img, 2, 2, 4, 4); }