Your sample uses
webimagecontrol1.URL := 'data:image/png;base64,' + GetBase64Image(webimagecontrol1.ElementHandle, 100,100);
To be honest, I would have never expected that instead of using Width/Height or ResizeImage of the component I need to do this rather unusual method. This is not the expected Delphi way...
And even if I knew that there exists a function GetBase64Image in WebLib.WebTools, it is declared there as function GetBase64Image(AImage: TJSHTMLElement): string;
with no sizing parameters at all. Only a closer research in the Core Source instead of the Component Library Source reveals this declaration: function GetBase64Image(AImage: TJSHTMLElement; AWidth: integer = 0; AHeight: integer = 0): string;.
So how should one know that this function exist with these parameters?
Now, while the small sample project works with respect to resizing, in my app it fails in the call to GetBase64Image in the line that says var dataURL = canvas.toDataURL("image/png");
this.GetBase64Image = function (AImage, AWidth, AHeight) {
var Result = "";
var s = "";
var m = null;
s = "";
m = AImage;
function getBase64Image(img) {
var canvas = document.createElement("canvas");
if (AWidth == 0) {
canvas.width = img.width; }
else {
canvas.width = AWidth; }
if (AHeight == 0) {
canvas.height = img.height; }
else {
canvas.height = AHeight; }
var ctx = canvas.getContext("2d");
if ((AWidth == 0) || (AHeight == 0)) {
ctx.drawImage(img, 0, 0); }
else {
ctx.drawImage(img, 0, 0, AWidth, AHeight); }
var dataURL = canvas.toDataURL("image/png"); <<====== Error
return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
}
s = getBase64Image(m);
Result = s;
return Result;
};
With this error:
What does this error mean and how can I prevent this?