Size of saved figure differs from size of frame2im(getframe(gcf))
조회 수: 4 (최근 30일)
이전 댓글 표시
I need to create big images in which displaying lot of annotations, but my computer has a low screen resolution 1366x768. So I looked on this site for a workaround to get bigger figures, and I found the command set(gcf, 'Position', get(0, 'Screensize')) which sets the figure size to 2134x1095 (I don't why this particular value though... is there a way to create figures with custom size in pixels?).
However, when using the frame2im(getframe(gcf)) command I get a 701x1366x3 matrix instead of a 1095x2134x3 matrix, am I doing something wrong? This is just an example to replicate the problem
clc; clear all; close all
figure('visible','off')
set(gcf, 'Position', get(0, 'Screensize'))
saveas(gcf, 'aaa.png')
im = frame2im(getframe(gcf));
[size(im) ; size(imread('aaa.png'))]
댓글 수: 0
답변 (1개)
Ameer Hamza
2020년 8월 27일
편집: Ameer Hamza
2020년 8월 27일
saveas() is not a good option for exporting high-resolution images. Use exportgraphics() and specify the required resolution. See this example: https://www.mathworks.com/help/releases/R2020a/matlab/ref/exportgraphics.html#mw_b4d91f8c-574f-4574-89af-37d54c5a182b.
exportgraphics() was introduced in R2020a, for older versions, see print(). For example
print('filename.jpg', '-r300'); % for printing at 300dpi
or export_fig package from here: https://www.mathworks.com/matlabcentral/fileexchange/23629-export_fig
print('filename.jpg', '-r300');
댓글 수: 7
Ameer Hamza
2020년 8월 28일
Ok. If you want to set the width and height of the figure in pixels, then you can specify a four-element vector like this [x y w h]. Where x is the distance (in pixels) from the left edge of screen, and y is the distance from the bottom of the screen. w and h are the width and height of the figure window.
set(gcf, 'Position', [0 0 500 500])
This command will set the figure window to the bottom left corner and set the width and height to 500 each.
참고 항목
카테고리
Help Center 및 File Exchange에서 Printing and Saving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!