Bodmer / TJpg_Decoder

Jpeg decoder library based on Tiny JPEG Decompressor
Other
228 stars 43 forks source link

Can you decode html canvas dataurls? #72

Closed MrFarePlay closed 10 months ago

MrFarePlay commented 10 months ago

I'm using an esp32 to serve an html page and create a websocket connection.

The page asks the user to select an image. After selecting the image the page will will draw it in a canvas, get the data as a jpeg dataurl using:

canvas.toDataURL('image/jpeg', 0.1 /*qualtiy*/);

then send the dataurl using the websocket back to the esp32 to draw it on a tft screen.

Currently I'm stuck at this part. The dataurl received doesn't seem do anything with TJpgDec.drawJpg. Also using TJpgDec.getJpgSize returns zero for both w and h.

Any help would be apricated.

MrFarePlay commented 10 months ago

Sorry for the post. The answer is yes 😂 just use base64 to decrypt the dataurl and you can just use it in TJpg directly.

Don't forget to tft.setSwapBytes(true);