app designer HTML object image file reloaded afresh

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">');

답변 (1개)

Hornett
Hornett 2023년 11월 6일
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.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2020a

태그

질문:

2022년 1월 16일

답변:

2023년 11월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by