Update Image of a uiimage element in a Web App

조회 수: 17 (최근 30일)
Christian Idzik
Christian Idzik 2021년 6월 13일
댓글: J. Alex Lee 2021년 6월 17일
Hi everyyone,
I developed a GUI with the AppDesigner in Matlab 2020b.
Then I complied it to a Web App on a linux server. It runs quite good, however one strange problem occur.
On that GUI, I have an uiimage element whose image should be dynamically loaded.
The name of the picture is always the same but it changes due to some user inputs. So the code is always e.g. app.Image.ImageSource = 'picture1.png';
So first I load the picture into the uiimage element, that works.
If new user inputs demand some changes of the picture, I reset the uiimage element to app.Image.ImageSource = '';,(that seems to work) Then the new picture is generated and after that I use the function rehash to update the folder and the new picture should be loaded.
But it only shows the picture which was loaded first, on the server there is only the new one.
It seems that the old picture is somehow cached and because the name is the same, the old image is simply reloaded.
Note that no error message is in the log, the problem does not occur while testing in matlab (before compiling it to a web app).
EDIT: I have rather the same problem as described here
I used the proposed answer and it works if I am using it in the enviroment of the App designer but as a Web App imgArray = 'picture.png' and app.Image.ImageSource = imgArray; does not work. In fact, the uiimage is empty.
Does anyone have an idea what the problem could be?
Thanks in advance!
Best
Chris
  댓글 수: 3
Christian Idzik
Christian Idzik 2021년 6월 15일
What do you mean by generate new files? Should I delete the old picture in the sessions folder in the web app server and then just create new ones, maybe with a timpe stamp, so that they are unique?
J. Alex Lee
J. Alex Lee 2021년 6월 15일
yes that is what i mean

댓글을 달려면 로그인하십시오.

답변 (1개)

Aghamarsh Varanasi
Aghamarsh Varanasi 2021년 6월 16일
편집: Aghamarsh Varanasi 2021년 6월 16일
Hi,
This is intended behaviour. As the filename of the image is not changed, as a part of optimization, the image is not reloaded. As a workaround, you can read the data from the image file and update the 'ImageSource' as follows.
imgLoad = imread('picture1.png');
app.ImageFixedFile.ImageSource = imgLoad;
For more information you can refer to this community post. In this post the use case also includes writing data to the image file, but the later half replicates your question.
  댓글 수: 2
Christian Idzik
Christian Idzik 2021년 6월 16일
Thanks!
Yeah I tried that and it works if I run the app in App Designer.
But it does not work if I use the app as a web app.
I am using Matab2020b und the MATLAB WebAppServer
Loading the picture by imread to uiimage results in a empty uiimage
J. Alex Lee
J. Alex Lee 2021년 6월 17일
It seems to me that if this is intended behavior, the class should come with a method that forces a refresh...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Web App Server에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by