0

I want to save a frame as an image in png format with saveas command. Although my image's size is 640X480 (gcf), the saved images size is 1201x901 and spaces white color.(like a bold white border).So I want the image to be saved 640x480. I tried transparent background but it didn't work. How can I fix this problem?

F(j) = getframe(gcf);
fname='C:\...'
saveas(gcf, fullfile(fname, 'newImage'), 'png');
tshepang
  • 12,111
  • 21
  • 91
  • 136
lacy
  • 13
  • 1
  • 6

2 Answers2

1

Try this,

set(gca,'position',[0 0 1 1],'units','normalized')

or you can try the imcropfunction.

SamuelNLP
  • 4,038
  • 9
  • 59
  • 102
0

If you aren't overlaying any graphics over the image, then save the image data directly using imwrite, rather than exporting a figure containing the image to png.

If you are overlaying graphics then the export_fig function (available for download on the MATLAB File Exchange) will automatically crop the whitespace around the figure. In this case use:

export_fig(fullfile(fname, 'newImage'), '-png', '-a1', '-native');
user664303
  • 2,053
  • 3
  • 13
  • 30