Arduino

Reference Language | Libraries | Comparison | Changes

TFTLibrary > TFT

## PImage.width

#### Description

Checks the width of the PImage object.

#### Syntax

image.width();

#### Parameters

none

#### Returns

int : the image's width in pixels

#### Example

// this example looks for a file named "logo.bmp"
// on the SD card, and renders it to the screen
#include <Esplora.h>
#include <SD.h>
#include <SPI.h>
#include <TFT.h> // Arduino TFT library
#define SD_CS 8 // Chip select line for SD card in Esplora
PImage logo;
void setup() {
// initialize the screen
EsploraTFT.begin();
// initialize the SD card
SD.begin(SD_CS);
// set the background the black
EsploraTFT.background(0, 0, 0);
// load the image into the named instance of PImage
logo = EsploraTFT.loadImage("arduino.bmp");
// if it is a valid image file, turn the Esplora's LED green
if (logo.isValid()) {
Esplora.writeGreen(255);
}
else{
// if it is not valid, turn the LED red
Esplora.writeRed(255);
}
}
void loop() {
// randomly draw the image on screen
int x = random(EsploraTFT.width() - logo.width());
int y = random(EsploraTFT.height() - logo.height());
EsploraTFT.image(logo, x, y);
delay(1500);
}
[Get Code]

#### See also

- image
- loadImage?()
- isValid?()
- PImage.height()

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

### Share

### This link has expired.
Please re-subscribe to our Newsletters.

### Subscribe to our Newsletters

Email

Please enter a valid email to subscribe

Arduino Newsletter
Arduino Store Newsletter

### Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy

###### Newsletter

- ©2015 Arduino
- Copyright Notice
- Contact us
- Careers