修改文件FileReader的源代码

时间:2015-08-19 11:47:14

标签: javascript html5 filereader

所以我有一个通过FileReader读取的图像,代码如下:

var reader = new FileReader();

reader.onload = function (e) {
  var canvas = document.createElement("canvas");
  var context = canvas.getContext("2d");
  var imageObj = new Image();
  imageObj.src  = e.target.result;
  imageObj.onload = function(){
    //
    canvas.width = this.width;
    canvas.height = this.height;
    // Move them before drawing anything.
    context.drawImage(imageObj, 0,0);
    context.font = "40pt Calibri";
    context.fillText("My TEXT!", 20, 20);
    console.log(e.target.result);
    console.log(canvas.toDataURL("image/jpeg"));
    BuildingService.addFile({file: file, filename: guid});
    category.Pictures.push({offlineFoto: canvas.toDataURL(), FileNameOnDevice: guid});
  };

    leftToProcess--;
    if (leftToProcess == 0) {
        $scope.loadingCat = false;
        $scope.loadingSubCat = false;
    }
    $scope.$apply();
};
reader.readAsDataURL(file);

然后在我BuildingService.addFile()的行上添加文件,但现在它仍然包含该文件的原始数据。

但我不知道如何修改文件对象,新的base64图像数据在文件中。

那你怎么做呢?

0 个答案:

没有答案