PImage.width()
描述
取得 PImage
物件中存放的图片的宽度。
语法
image.width();
参数
无参数
回传
int
:图片宽度,单位为像
范例
// 把 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"); } } void loop() { // 随机的挑选图片显示的位置 int x = random(screen.width() - logo.width()); int y = random(screen.height() - logo.height()); screen.image(logo, x, y); delay(1500); }
See also
- image
- loadImage( )
- PImage.isValid( )
- 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.