Canvas與Image互轉

看風景就發表於2016-01-08

function fImageToCanvas(image){
  var oCanvas = document.createElement("canvas");
  oCanvas.width = image.width;
  oCanvas.height = image.height;
  oCanvas.getContext("2d").drawImage(image,0,0);
  return oCanvas;
}

function fCanvasToImage(canvas){
  var oImage = new Image();
  image.src = canvas.toDataURL("image/png");
  return image;
}

 

參考:http://blog.csdn.net/renfufei/article/details/9855519

相關文章