1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
export class FormulaireComponent implements OnInit
{
public divH: number = 0;
public divW: number = 0;
selectedFile = null;
context: CanvasRenderingContext2D;
@ViewChild("mycanvas") mycanvas;
constructor() { }
ngOnInit() {}
// Après le choix de l'image
onFileSelected(event){
let canvas = this.mycanvas.nativeElement;
let context = canvas.getContext('2d');
context.clearRect(0, 0, 300, 300);
let self = this;
// Rendu de l'image sur le canvas
var render = new FileReader();
render.onload = function(event: any) {
var img = new Image()
img.onload = function() {
canvas.width = img.width;
canvas.height = img.height;
self.divW = img.width;
self.divH = img.height;
context.drawImage(img,0,0);
console.log ("img.onload: " + self.divW + " - naturalW " + img.naturalWidth + " - width " + img.width);
};
img.src = event.target.result;
//teste si l'image est bien chargé
if(!img.complete) { console.log("chargé")} else { console.log("pas encore")}
};
render.readAsDataURL(event.target.files[0])
this.unTest()
}
unTest(){
console.log("unTest: " + this.divW)
}
} |
Partager