Canvas Gadget to Image URL

Share your advanced knowledge/code with the community.
BinoX
Posts: 7
Joined: Mon Aug 01, 2016 4:13 pm

Canvas Gadget to Image URL

Post by BinoX »

Code: Select all

Procedure.s CanvasToImageURL(gadget, plugin)
  
      thingy = GadgetID(gadget)
      imagedata.s = ""
      If plugin = #PB_ImagePlugin_PNG
        !v_imagedata = v_thingy.canvas.toDataURL("image/png")
      ElseIf plugin = #PB_ImagePlugin_JPEG
        !v_imagedata = v_thingy.canvas.toDataURL("image/jpeg")
      EndIf
            
      ProcedureReturn imagedata
  
EndProcedure
As EncodeImage is not currently supported I wrote a quick procedure to let me export a canvas as an Image URL.

This could probably be modified to use Images instead (maybe by creating an invisible canvas and transferring the image), but this was sufficient for my purposes. I thought that someone might find it useful.

It takes the gadget as the first argument and the second is the #PB_ImagePlugin_* although BMP doesn't seem to be supported as an export format.

Apologies if this has already been done. Although if there is a built in method that I don't know about, please let me know.