-
How can I get the dimensions of an image from the sd card? Lovyangfx supports bmp, jpg and png files but for me impossible to recover the dimensions? I need it to allocate a buffer of the same size. I don't know if this method already exists? Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Image info from the decoders (png,bmp,jpeg,qoi) is private during decoding because lgfx image functions are harmonized into a common transaction-based syntax, which is designed to be used in imperative mode. so it's either you know the size in advance, or you speculate on it e.g. setup a sprite, draw the image in there without worrying about buffer overflows |
Beta Was this translation helpful? Give feedback.
-
bool parsePng(String filename, int16_t* width, int16_t* height)
{
File file = SD.open(filename);
if (!file)
{
SPI_busy = false;
return false;
}
byte table[32];
for (int i = 0; file.available() && i < 32; i++)
{
table[i] = file.read();
}
*width=table[16]*256*256*256+table[17]*256*256+table[18]*256+table[19];
*height=table[20]*256*256*256+table[21]*256*256+table[22]*256+table[23];
file.close();
return true;
} I finally make this short code for parsing a png image and retrieve dimensions. |
Beta Was this translation helpful? Give feedback.
-
bool parseBmp(String filename, int16_t* width, int16_t* height)
{
File file = SD.open(filename);
if (!file)
{
SPI_busy = false;
return false;
}
byte table[32];
for (int i = 0; file.available() && i < 32; i++)
{
table[i] = file.read();
Serial.print(String(table[i]) + ",");
}
*width=table[15]*256*256*256+table[16]*256*256+table[17]*256+table[18];
*height=table[19]*256*256*256+table[20]*256*256+table[21]*256+table[22];
file.close();
return true;
}```
and for the bitmap! |
Beta Was this translation helpful? Give feedback.
I finally make this short code for parsing a png image and retrieve dimensions.