MATLAB Answers

How do I update an image object in App Designer?

146 views (last 30 days)
I'm using the App Designers image object to display a jpeg. The code modifies the image data and then writes it back to the jpeg. However if I reload it in the image object it uses the original jpeg - presumably cached and not updated. The only way I have found to make it use the new image is to use a different filename for the modified image and then point to the new file. The image object appears to have a reset function but trying to use it causes a 'no method' error.
  4 Comments
Gary Burton-Wilcock
Gary Burton-Wilcock on 28 Jun 2019
Hi Geoff - for this example yes I'm just adding 25 just to force a change on the image. I do see the image change if, oustide Matlab, I look at the file that is written after each press of the modify button. However, pressing the reload button doesn't refresh the image in the Matlab app. It feels like Matlab has cached the original image and changing the image source property of the image control (but with a filename that it has already seen) doesn't force it to renew its data. I can't see any way to make it drop that data without restarting the app.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 28 Jun 2019
Yes, I can observe the same behaviour. I've not been able to find exactly which class is responsible for the problem yet, it's not the Image class itself, the class mark itself as dirty every time you set the ImageSource property. It must be something else upstream that sees that the filename hasn't changed and hence do not update the display. I'll report the problem to matlab.
On the other hand, personally, I'd never give a filename to ImageSource, instead I'd passed an image array:
function readButtonPushed(app, event)
app.img = imread("lena512.bmp");
app.Image.ImageSource = repmat(app.img, 1, 1, 3); %ImageSource wants a RGB image, not a greyscale image
% the image appears in the Image control
end
% Button pushed function: modifyButton
function modifyButtonPushed(app, event)
app.img = app.img + 25;
end
% Button pushed function: reloadButton
function reloadButtonPushed(app, event)
app.Image.ImageSource = repmat(app.img, 1, 1, 3);
end
which doesn't have the same problem.
  5 Comments
Lucas Moreira
Lucas Moreira on 29 Oct 2020
app.Image.ImageSource only accept the image path, your img is a uint8 image, got it? you need to pass the path, like: "C:\imageName.jpg"

Sign in to comment.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by