locked
convert canvas to base 64

    Question

  • I want to save my canvas to base64 in order to save to my database.

    function

    displayImageFromFile(imgFile, imgTag) {

     

    var canvas = document.getElementById('testcanvas');

    canvas.setAttribute(

    'width', 825);

    canvas.setAttribute(

    'height', 840);

    var ctx = canvas.getContext('2d');

    for (var i = 0; i < imgFile.length; i++) {

     

    url = URL.createObjectURL(imgFile[i],

    false);

    var locationx = 0;

    var locationy = 0;

    img =

    new Image();

    img.src = url;

    var drawCanvasImage = function (ctx, img) {

    return function () {

    ctx.drawImage(img, 0, 0, 320, 240, locationx, locationy, 400, 400);

    if (locationx == 410) {

    locationx = 0;

    locationy += 430;

    }

    else {

    locationx += 410;

    locationy += 0;

    }

    }

    }

    img.onload = drawCanvasImage(ctx, img);

    }

    }


    1002614D

    Tuesday, July 10, 2012 6:15 AM

Answers