Created
July 5, 2012 11:00
-
-
Save abicky/3052980 to your computer and use it in GitHub Desktop.
Create HTMLImageElement from HTMLCanvasElement and HTMLCanvasElement from HTMLImageElement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "js/web.jsx"; | |
class Util { | |
static function image2Canvas(image : HTMLImageElement) : HTMLCanvasElement { | |
var document = dom.window.document; | |
var canvas = document.createElement("canvas") as HTMLCanvasElement; | |
canvas.width = image.width; | |
canvas.height = image.height; | |
var ctx = canvas.getContext("2d") as CanvasRenderingContext2D; | |
ctx.drawImage(image, 0, 0); | |
return canvas; | |
} | |
static function canvas2PNGImage(canvas : HTMLCanvasElement) : HTMLImageElement { | |
var document = dom.window.document; | |
var image = document.createElement("img") as HTMLImageElement; | |
image.src = canvas.toDataURL(); | |
return image; | |
} | |
static function canvas2JPEGImage(canvas : HTMLCanvasElement) : HTMLImageElement { | |
var document = dom.window.document; | |
var image = document.createElement("img") as HTMLImageElement; | |
image.src = canvas.toDataURL("image/jpeg"); | |
return image; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment