Is possible to pass an input image from an html form to matlab using javascript?
Show older comments
Hello everyone. I'm building a graphic interface using MATLAB with HTML, CSS, and JavaScript. I'm working on a small form where users can upload an image, and this image needs to be sent to MATLAB to be displayed using the imshow() function. This is what I'm doing:
fig = uifigure("Position",[100 100 900 500]);
h = uihtml(fig,"Position",[0 0 900 500]);
h.HTMLSource = 'immagineInput.html';
h.HTMLEventReceivedFcn = @displayNumber;
function displayNumber(src,event)
name = event.HTMLEventName;
if strcmp(name,'ButtonClicked')
number = event.HTMLEventData;
b64 = matlab.net.base64decode(number);
imshow(b64);
end
end
But the problem is that it displays an empty window, without the image.
The JavaScript code is the following:
function setup(htmlComponent) {
var input = document.getElementById("immagine");
var submit = document.getElementById("submit");
submit.addEventListener("click", function () {
var file = input.files[0];
var reader = new FileReader();
reader.onloadend = function () {
htmlComponent.sendEventToMATLAB("ButtonClicked", reader.result);
};
reader.readAsDataURL(file);
});
}
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Report Generator in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!