Image Widget display error


I put the image bin in nand flash without filesystem. I have parsed the bin file into lv_img_dsc_t, but it cannot be used normally after setting to image widget. Image widget displays “No data”. I made sure that the data has been parsed.

What MCU/Processor/Board and compiler are you using?


What do you want to achieve?

Display image normal

What have you tried so far?

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/
lv_obj_t* lv_image = lv_img_create(tab1, NULL);
extern const lv_img_dsc_t bg4323;
lv_img_dsc_t flash_img;
lv_obj_set_size(lv_image, flash_img.header.w, flash_img.header.h);
lv_obj_align(lv_image, NULL, LV_ALIGN_CENTER, 0, 0);
lv_img_set_src(lv_image, &flash_img);

void loadBitmap(lv_img_dsc_t *image)
	uint8_t *pbuf;
	uint32_t file_size = 0x3eb4 - 4;
	int secTime = file_size/4096;
	int secOff = file_size%4096;
	int i;
	dbg_printf(" secTime = %d, secOff = %d\r\n", secTime, secOff);

	pbuf = lv_mem_alloc(0x3eb4-4);

	for (i=0; i<secTime; i++) {
		SPI_Flash_Read(&pbuf[i*4096], 4+i*4096, 4096);
	if (secOff>0) {
		SPI_Flash_Read(&pbuf[secTime*4096], 4+secTime*4096, secOff);

	image-> = LV_IMG_CF_TRUE_COLOR;
	image->header.always_zero = 0;
	image->header.w = 100;
	image->header.h = 100;
	image->data_size = 0x3eb4 - 4;	//去掉4字节的头,剩余的就是图片数据流长度
	image->data = pbuf;
	dbg_printf(" pbuf = [0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x]\r\n",
		pbuf[0x580], pbuf[0x581], pbuf[0x582], pbuf[0x583], pbuf[0x584],
		pbuf[0x3970], pbuf[0x3971], pbuf[0x3972], pbuf[0x3973], pbuf[0x3974]);

## Screenshot and/or video
If possible, add screenshots and/or videos about the current state.

> Blockquote

I found that in lv_img_src_get_type, the u8_p [0] value has been changing, but the value of printed after my loadBitmap is 0x04.

This problem can be solved by declaring flash_img as a global variable instead of a local variable.

That makes sense. flash_img needs to be referenced after the calling function returns. When you make it an automatic variable in the function, it gets allocated on the stack and is thus corrupted when the function exits. Making it a global variable (or static within the function) will keep it allocated for the lifetime of the program.