當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Arduino TFT - PImage.isValid()用法及代碼示例

說明

檢查 PImage 的命名實例是否引用了有效的位圖文件。

用法

image.isValid();

參數

返回

布爾值

示例

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

  // draw the image on the screen starting at the top left corner
  EsploraTFT.image(logo, 0, 0);

}

void loop() {

}

相關用法


注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 TFT - PImage.isValid()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。