当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Arduino TFT - PImage.width()用法及代码示例


说明

检查 PImage 对象的宽度。

用法

image.width();

参数

返回

int:图像的宽度(以像素为单位)

示例

// 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);

}

相关用法


注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 TFT - PImage.width()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。