我们已经用 a子储存图像。 当我们试图将图像转换成基64时。 从事精细 j工作的法典,但法典并非单体。
<javascript Code:
function getBase64Image(imgUrl, callback) {
var img = new Image();
// onload fires when the image is fully loadded, and has width and height
img.onload = function(){
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
var dataURL = canvas.toDataURL("image/png"),
dataURL = dataURL.replace(/^data:image/(png|jpg);base64,/, "");
callback(dataURL); // the base64 string
};
// set attributes and src
img.setAttribute( crossOrigin , anonymous ); //
img.src = imgUrl;
}
this.getBase64Image("imageURL", function(base64image){
console.log(base64image);
});
它是在javascript进行工作罚款的,但ular在错误之下。
Access to image at https://examplecros.s3.us-east-2.amazonaws.com/images5.jpg from origin http//localhost:4200 has been blocked by CORS policy: No Access-Control-Allow-Origin header is present on the requested resource.
5.jpg:1
Failed to load resource: net::ERR_FAILED