当前位置:网站首页>esp12f + tft 显示图片问题
esp12f + tft 显示图片问题
2022-07-29 22:53:00 【おもいね】
问题描述
#include <TFT_eSPI.h>
#include <TJpg_Decoder.h>
在使用这两库时候,发现图片虽然显示后,但会强制esp8266复位,一直没找到原因,经过一次一次测试,发现TJpg_Decoder仅仅是一个tjpg图片解码的库,并不能之间显示图片,而且库中提供了一个回调函数,来调用屏幕显示位图的函数。
解决
注意这个函数
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap)
{
if (y >= tft.height())
return 0;
tft.pushImage(x, y, w, h, bitmap);
// Return 1 to decode next block
return 1;
}
在setup中添加这个回调函数即可
下面就是全部代码:
只需要将图片换成自己的就可以完整的显示一个图片。
#include <Arduino.h>
#include <TFT_eSPI.h> // Include the graphics library (this includes the sprite functions)
#include <TJpg_Decoder.h>
#include<EEPROM.h>
TFT_eSPI tft = TFT_eSPI(); // Create object "tft"
TFT_eSprite img = TFT_eSprite(&tft); // Create Sprite object "img" with pointer to "tft" object
#include "../include/jpeg/jpeg1.h"
#define LCD_BC 5 // 这个是我的硬件调节背光的IO,大家可以自己忽略
// TFT屏幕输出函数
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap)
{
if (y >= tft.height())
return 0;
tft.pushImage(x, y, w, h, bitmap);
// Return 1 to decode next block
return 1;
}
void setup()
{
pinMode(LCD_BC,OUTPUT);// 这个是我的硬件调节背光的IO,大家可以自己忽略
analogWrite(LCD_BC,0);// 这个是我的硬件调节背光的IO,大家可以自己忽略
Serial.begin(115200);
tft.begin();
tft.fillScreen(TFT_BLUE);
// The jpeg image can be scaled by a factor of 1, 2, 4, or 8
TJpgDec.setJpgScale(1);
TJpgDec.setSwapBytes(true);
TJpgDec.setCallback(tft_output);
}
void loop()
{
// Time recorded for test purposes
uint32_t t = millis();
// Get the width and height in pixels of the jpeg if you wish
uint16_t w = 0, h = 0;
TJpgDec.getJpgSize(&w, &h, panda, sizeof(panda));
Serial.print("Width = "); Serial.print(w); Serial.print(", height = "); Serial.println(h);
// Draw the image, top left at 0,0
TJpgDec.drawJpg(0, 0, panda, sizeof(panda));
// How much time did rendering take (ESP8266 80MHz 473ms, 160MHz 266ms, ESP32 SPI 116ms)
t = millis() - t;
Serial.print(t); Serial.println(" ms");
// Wait before drawing again
delay(2000);
}
边栏推荐
- 刀具更换策略问题(完工)
- DNA偶联二维过渡金属硫化物|DNA修饰贵金属纳米颗粒|使用方法
- 利用go通道channel实现互斥锁
- Embedded system driver primary [1] - kernel module _ compilation method
- 【面试:并发篇29:多线程:volatile】原理
- bgp基础配置和宣告
- 《MySQL DBA封神打怪之路》专栏学习大纲
- The sequence table of the linear table (the dry goods are full of sharing ~ contains all the function codes of the sequence table~
- 一级建造师从业者面试需要注意什么问题?
- high-level-rest-client 判断索引是否存在
猜你喜欢
J9数字论:为什么我们需要Web3?
将文件流转成file文件后使用luckysheet回显数据
The second round of the real offer harvester~ How does the big factory inspect the candidates?(with detailed answer)
Redis和MySQL如何保持数据一致性
地狱挖掘者系列#1
【C语言】链表详解(无头单向非循环)
Foxmail是什么邮箱?
【openlayers】地图【一】
一级建造师从业者面试需要注意什么问题?
How to realize object selection in canvas (5)
随机推荐
WSDM‘22推荐系统论文梳理
MySQL主备切换
J9数字论:为什么我们需要Web3?
通过 FileUploader 的初始化,了解 SAP UI5 应用的 StaticArea 初始化逻辑
bgp基础配置和宣告
【面试:并发篇29:多线程:volatile】原理
The first round of the real offer harvester~ How does the big factory inspect the candidates?(with detailed answer)
【移动应用开发】2022/2023 年 8 大移动应用程序开发趋势
什么是色选机(color sorter)?
JetsonNano学习(六)Jetson踩过的大坑及解决方法___持续更新
@Autowired与@Resource区别
汉字的URL转义字符函数
DNA修饰碳纳米管|DNA修饰单层二硫化钼|DNA修饰二硫化钨(注意事项)
SAP ABAP Netweaver 容器化的一些前沿性研究工作分享
DNA修饰的上转换纳米材料|聚胞苷酸Poly-C DNA修饰的氧化石墨烯|解析说明
OR63 删除公共字符
OR62 倒置字符串
DNA脱氧核糖核酸修饰四氧化三铁|DNA修饰氧化锌|使用方法
NetWorker Knowledge Corner|Easy to get an offer [Networker Interview Questions] What is the difference between a Layer 3 switch and a router?
你真的了解Redis的持久化机制吗?