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


Arduino TFT - loadImage()用法及代碼示例

說明

將圖像文件從 SD 卡加載到 PImage 的命名實例中。 TFT 庫能夠從 SD 卡的根目錄讀取 .bmp 文件並將它們顯示在屏幕上。圖像可以小於或大於屏幕分辨率 (160x128),但 Arduino 上沒有用於圖像處理的方法。在將圖像放入 SD 卡之前,應該調整它們的大小。 TFT 庫能夠從 SD 卡的根目錄讀取 .bmp 文件並將它們顯示在屏幕上。僅可以加載 24 位 bmp 圖像。

用法

screen.loadImage(name);

參數

name: char 數組,要讀取的 SD 卡中圖片的名稱

返回

加載的圖像

示例

// 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 - loadImage()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。