We are using Ionic and Angular.
After clicking image, we need to rotate the image on canvas. If we pass jpg, it rotates as needed but when we pass base64, it doesn't rotate the image.
Below is our code:
home.html
<canvas id="c" ></canvas>
home.ts
ngOnInit() {
let img = "//base64 string";
setTimeout(() => {
this.rotateBase64Image(img, 'callback');
},1000);
}
rotateBase64Image(base64data, callback) {
var canvas = document.getElementById("c");
var ctx = (<any>canvas).getContext("2d");
var image = new Image();
image.src = base64data;
image.onload = function() {
var size = '200';
canvas.setAttribute('width', image.width.toString());
canvas.setAttribute('height', image.height.toString());
ctx.rotate(90 * Math.PI / 180);
ctx.drawImage(image, 0, -image.height);
console.log(""+callback+"('"+(<any>canvas).toDataURL()+"')");
};
}
callback(base64data) {
console.log(base64data);
}
Here is a screenshot of canvas when base64 is passed: