You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Doctor Who edited this page Jan 26, 2023
·
2 revisions
Suppose you have a database stored in the variable db, containing a table images with the following contents:
id (INTEGER)
image (BLOB)
1
image stored as BLOB
You want to display the image, either on a canvas, or directly as an image element on your page.
//[...]varstmt=db.prepare("SELECT image FROM test WHERE id=$id");// SQL statementvaruarray=stmt.getAsObject({$id:1})['image'];// UInt8Array containing the bytes of the image// (of course you can use other API methods to query your databasestmt.free();// Free the memory used by the statement// The tricky part : create a blob url to your image, that you can use anywherevarobjurl=window.URL.createObjectURL(newBlob([uarray]));varimg=newImage();img.src=objurl;img.onload=function(){// do something with your image}