1.QuecPython+LVGL显示图片
由于官方提供的显示图片函数使用失败,为了能在屏幕上显示图片,通过对出厂脚本的分析,成功使用LVGL显示图片
(1)代码
import lvgl as lv
from tp import gt9xx
from machine import LCD
from machine import Pin
mipilcd = LCD() #LCD实例化
mipilcd.lcd_init(type=3,width=480,hight=854)
gpio1 = Pin(Pin.GPIO27, Pin.OUT, Pin.PULL_PU, 1)
gpio2 = Pin(Pin.GPIO8, Pin.OUT, Pin.PULL_PU, 1)
lv.init()
disp_buf1 = lv.disp_draw_buf_t()
buf1_1 = bytes(480*854*2)
disp_buf1.init(buf1_1, None, len(buf1_1))
disp_drv = lv.disp_drv_t()
disp_drv.init()
disp_drv.draw_buf = disp_buf1
disp_drv.flush_cb = mipilcd.lcd_write
disp_drv.hor_res = 480 #此处基于实际的屏幕来设置水平分辨率
disp_drv.ver_res = 854 #此处基于实际的屏幕来设置垂直分辨率
disp_drv.sw_rotate=1 #因为横屏,所以需要旋转
disp_drv.rotated = lv.DISP_ROT._270 #旋转角度
disp_drv.register()
#GT911初始化
#tp_gt911 = gt9xx(irq=10,reset=11)
tp_gt911 = gt9xx(irq=40,reset=20)
tp_gt911.activate()
tp_gt911.init()
gpio40 = Pin(Pin.GPIO40, Pin.OUT, Pin.PULL_PD, 0)
tp_gt911.read_xy()
#LVLG触摸注册
indev_drv = lv.indev_drv_t()
indev_drv.init()
indev_drv.type = lv.INDEV_TYPE.POINTER
indev_drv.read_cb = tp_gt911.read
indev_drv.register()
#启动LVGL 线程
lv.tick_inc(5)
lv.task_handler()
scr = lv.obj()
class MyWidget():
def __init__(self, scr):
# Create an image from the png file
Smain_quectel = lv.img(scr)
Smain_quectel.set_pos(0,0)
Smain_quectel.set_size(854,480)
Smain_quectel.add_flag(lv.obj.FLAG.CLICKABLE)
Smain_quectel.set_src('U:/th.png')
Smain_quectel.set_pivot(0,0)
Smain_quectel.set_angle(0)
MyWidget(scr)
lv.scr_load(scr)
(2)效果图
注意:
1)图片不能过大,超过开发板内存,传入之后为大小为0,无意义
2)图片要求,位深度为32,其余大小自行测试