user1008374
user1008374

Reputation: 41

Save image from axes in MATLAB

I generate a picture in an axes that is called newIM when I click on the apply button. Now, I want to save this new picture in a jpg, gif, bmp or whatever file when I push the save button.

This is what I had:

pathname = 'D:\pictures\';
filename = 'Test.bmp';
both = strcat(pathname, filename);
imshow(both);
imsave('test','*.jpg')

But this is only for a Test.bmp and not for the picture in newIM.

How can I make this variable?

Upvotes: 4

Views: 7339

Answers (2)

bdecaf
bdecaf

Reputation: 4732

If it's in some gui or other plots I usually use copyobj to copy the axes containing the picture and add them to a new (usually hidden) figure window.

Upvotes: 0

Xyand
Xyand

Reputation: 4488

Use getfame:

F = getframe(gcf);
image(F.cdata);
imwrite(F.cdata, 'file.jpg');

Upvotes: 5

Related Questions