Description
By this article https://blog.littlevgl.com/2018-10-05/png_converter.
I can decode sd’s png file to png_decoded data by lodepng_decode_file()
,
but when set src to lv_img’s obj, the result that shown on the TFT seems a mistake.
How to fix the issue?
(The code as the following part.)
What MCU/Processor/Board and compiler are you using?
- ESP32
- lvgl 6.0.2
What do you want to achieve?
Wish to display sd’ png_file correctly.
What have you tried so far?
Code to reproduce
const char* png_filename = "/sd/images/08.PNG"; // this png file is PNG_RGBA8 type
static uint8_t* png_decoded;
uint32_t png_width, png_height;
LodePNG_format png_format=PNG_BADFORMAT;
uint8_t error = lodepng_decode_file(&png_decoded, &png_width, &png_height, &png_format, png_filename );
if(error) {
Serial.println(lodepng_error_text(error));
return;
}
Serial.printf("PNG : %s ; wxh : %dx%d ; format : %d\n", png_filename, png_width, png_height, png_format);
static lv_img_dsc_t png_dsc;
png_dsc.header.always_zero = 0; /*It must be zero*/
png_dsc.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA; /*Set the color format*/
png_dsc.header.w = png_width;
png_dsc.header.h = png_height;
png_dsc.data_size = png_width * png_height * 4;
png_dsc.data = png_decoded;
lv_obj_t * img_obj = lv_img_create(lv_scr_act(), NULL); /*Create the an image object in LittlevGL*/
lv_img_set_src(img_obj, &png_dsc);
The result on serial monitor :
PNG : /sd/images/08.PNG ; wxh : 320x240 ; format : 3
( format 3 is PNG_RGBA8 )
Screenshot and/or video
The result on TFT’s screen.