回覆列表
  • 1 # 使用者1430807591406

    /**

    * Convert an image

    * to a base64 string

    * @param {String} url

    * @param {Function} callback

    * @param {String} [outputFormat=image/png]

    */

    function convertImgToBase64(url, callback, outputFormat){

    var canvas = document.createElement("CANVAS"),

    ctx = canvas.getContext("2d"),

    img = new Image;

    img.crossOrigin = "Anonymous";

    img.onload = function(){

    var dataURL;

    canvas.height = img.height;

    canvas.width = img.width;

    ctx.drawImage(img, 0, 0);

    dataURL = canvas.toDataURL(outputFormat);

    callback.call(this, dataURL);

    canvas = null;

    };

    img.src = url;

    }

    這個方法試試吧!!!!

  • 中秋節和大豐收的關聯?
  • 五年級解方程155X-2X=18說出怎麼算要解釋清楚?