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');
有帮助吗?

解决方案

Try this,

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

or you can try the imcropfunction.

其他提示

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');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top