PImage.isValid()
描述
檢查 PImage 物件裡存放的圖片是否符合規範。
語法
image.isValid();
參數
無參數
回傳
boolean:如果存放的圖片符合規範回傳 true,反之回傳 false
範例
// 把 SD 卡中名為 "arduino.bmp" 的圖片顯示在螢幕上
#include <SPI.h>
#include <SD.h>
#include <TFT.h>
#define cs 10
#define dc 9
#define rst 8
TFT screen = TFT(cs, dc, rst);
PImage logo;
void setup() {
// 初始化 TFT 物件
screen.begin();
// 初始化 SD 卡
SD.begin();
// 設定背景色為黑色
screen.background(0, 0, 0);
// 載入圖片到 PImage 物件
logo = screen.loadImage("arduino.bmp");
if (!logo.isValid()) {
Serial.println("error while loading arduino.bmp");
}
// 從螢幕的左上角開始顯示圖片
screen.image(logo, 0, 0);
}
void loop() {
}
See also
- image
- loadImage( )
- PImage.width( )
- PImage.height( )
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.
