Closed fluxa closed 1 year ago
The problem is in the sketch. The following line only fetches a small part of the data, you have to keep calling it until all the data is retrieved:
buf_len = client->read(buf, len);
This should work but you might wish to add a time-out in the loop incase all the data is not received (sketch will lock up in loop otherwise):
uint8_t* ptr = buf;
while (buf_len < len) {
int32_t read_len = client->read(ptr, len);
if (read_len > 0) {
ptr += read_len;
buf_len += read_len;
}
}
The jpg can be scaled down by a factor of 1,2,4 or 8 to fit the screen (other ratios owuld require bilinear interpolation!).
This code should work:
uint8_t scale = 1;
while (w > tft.width()) {
scale *= 2;
w /= 2;
h /= 2;
}
while (h > tft.height()) {
scale *= 2;
h /= 2;
}
if (scale > 8) scale = 8;
TJpgDec.setJpgScale(scale);
// Draw the image, top left at 0,0
TJpgDec.drawJpg(xpos, ypos, buf, buf_len);
You might like to have a look at the fork here which supports streaming large images from the web without needing to allocate a buffer: https://github.com/SirCooper/TJpg_Decoder
Let me know if that works for you. @SirCooper has raised a pull request (in #52) but I have not implemented it yet.
Hi, I'm having a similar issue. I can't get the full image to be displayed on the TFT screen. I'm using the M5Stack Core2 (ESP32) platform, and here is the code:
Here's an example of how an image is rendered: https://drive.google.com/file/d/1jbd1YidgceKbn9TgsfUfybOOGcFRDVP4/view?usp=sharing
And this is the image URL: https://apod.nasa.gov/apod/image/0410/PassageOmbre_sm4.jpg
Also, how can I make the image fit the screen size?
Thank you!