app designer HTML object image file reloaded afresh

10 views (last 30 days)
I have an app designer program that captures a tab image and saves it into a file and uses it to create an HTML file for display using an HTML component. After each run, the image is recaptured and saved into a file with the same name. But the HTML component displays the very first image no matter what. Any fixes?
> app.TabGroup.SelectedTab=app.SolutionTab;pause(1)
> s = screencapture(app.pnlAnswer);
> imwrite(s,fname5);
> fprintf(fid,'%s\r\n','<h2>Kinematics Table</h2>');
> fprintf(fid,'%s\r\n','<img src="test5.jpg">');

Answers (1)

Hornett
Hornett on 6 Nov 2023
It seems that you are encountering an issue with the image not refreshing in the HTML component of "App Designer" in MATLAB.
To address this issue, you can use a workaround by creating a webpage with the code below. This code will update the content of the HTML page using JavaScript and pass the image from MATLAB to the HTML page.
Attaching the current timestamp as a query parameter to the image's "src" attribute, it will force the JavaScript to load the image again.
HTML page:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function setup(htmlComponent) {
htmlComponent.addEventListener("DataChanged", function(event) {
document.getElementById("dataDisplay").innerHTML = htmlComponent.Data;
});
}
</script>
</head>
<body>
<div id ="dataDisplay">
<img src="./test5.jpg">
</div>
</body>
</html>
MATLAB Code:
app.TabGroup.SelectedTab=app.Tab;
pause(1)
s = screencapture(app.pnlAnswer);
imwrite(s,fname5);
link = "<img src='test5.jpg?m="+num2str(now)+"'>"
app.HTML.Data = link;
Changing Startup function to load HTML page
app.HTML.HTMLSource = fullfile(pwd,'datachange.html'); % load HTML page in you HTML Component
To gain a more detailed understanding of the topic, I recommend referring to the following documentation: https://www.mathworks.com/help/matlab/ref/uihtml.html
I hope this information proves helpful in resolving your concern.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!