Save axes as jpg file in app designer

8 views (last 30 days)
J Wells
J Wells on 23 May 2022
Commented: Image Analyst on 23 May 2022
Hi there,
Im currently trying to code a save button so that the axes can be saved as a .jpg file. I found the following code:
F = getframe(handles.axes1);
Image = frame2im(F);
imwrite(Image, 'Image.jpg')
The problem is i dont want the file to save as "Image.jpg", but save with the name entered in a text field.
I tried:
F = getframe(handles.axes1);
Image = frame2im(F);
imwrite(Image, app.FileNameEditField.Value,'jpg')

Accepted Answer

Image Analyst
Image Analyst on 23 May 2022
Try
F = getframe(handles.axes1);
displayedImage = frame2im(F); % A screenshot of the entire figure, not just the image.
baseFileName = app.FileNameEditField.String; % String property, not Value I believe (if it's like GUIDE)
% Get file parts
[folder, bn, ext] = fileparts(baseFileName);
if isempty(folder)
folder = pwd;
end
% Change extension to PNG which gives an image with no compression
% artifacts, unlike JPG. Ignore any extension they put in there.
baseFileName = [bn, '.PNG'];
fullFileName = fullfile(folder, baseFileName); % Prepend folder.
fprintf('Writing image file "%s".\n', fullFileName);
imwrite(displayedImage, fullFileName)
  2 Comments
Image Analyst
Image Analyst on 23 May 2022
OK, thanks for catching that. It seems a bit consistent. Usually value is a number and String is a character array, at least that's the way it's in GUIDE. I believe it's similar in Microsoft Visual Studio those they use "Text" rather than "String". According to what you say, it seems like they're using Value for everything regardless of what type it is. I haven't started using app designer yet since I mostly work on legacy GUIDE programs or create new programs based on old legacy programs. Plus some functions (like impixelinfo) didn't work in App Designer until this last version.
I'm attaching a generic template App Designer GUI that I'll start using once they force me to start using App Designer.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by