(bitmap->data-uri {:keys [data width height], :as bitmap})
Returns a string containing a data URI for the given bitmap.
Source
(defn bitmap->data-uri
"Returns a string containing a data URI for the given bitmap."
[{:keys [data width height] :as bitmap}]
(let [image (promise)]
(STBImageWrite/stbi_write_png_to_func (reify STBIWriteCallbackI
(invoke [this context data size]
(let [buf (STBIWriteCallback/getData data size)
arr (byte-array (.remaining buf))]
(.get buf arr)
(deliver image arr))))
0 width height 1 data 0)
(let [^bytes barray (base64/encode @image)]
(str "data:image/png;base64," (String. barray "UTF-8")))))