필터 지우기
필터 지우기

How to save a figure's content as image?

조회 수: 44 (최근 30일)
John Wray
John Wray 2017년 3월 14일
댓글: Walter Roberson 2021년 1월 3일
I want to save the content of the figure without any other stuff like border, title etc.
For example, this is the figure.
But How to Save the Red Area Content Only???
  댓글 수: 2
Jan
Jan 2017년 3월 14일
Please explain how you want to save the file: Through a command or by using the menus?
K M Ibrahim Khalilullah
K M Ibrahim Khalilullah 2018년 6월 19일
I am fetching the same problem...I want to save from menu..

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2017년 3월 14일
편집: Jan 2017년 3월 14일
What about this:
F = getframe(gca);
imwrite(F.cdata, 'File.png');
Thios capture the contents of the currently active axes object. It is safer to provide teh axes' handle instead of gca.
  댓글 수: 8
Amrutamaya Behera
Amrutamaya Behera 2021년 1월 3일
편집: Amrutamaya Behera 2021년 1월 3일
Why doesn't this getframe() command always work properly. In some cases i noted when my XLim or YLim is higher than 1000 this command gets only somepart of full frame. Please help me out.
Walter Roberson
Walter Roberson 2021년 1월 3일
Are you passing a rectangle specfication to getframe ?
There is a challenge that axes size can change slightly depending on xlim / ylim; I have noticed a difference of between -1 to +2 pixels. It was not as simple as "limit over 1000 is 2 pixels bigger". I seem to recall that I traced it to a rounding issue, a round-trip calculation that algebraically "should" work out to convert pixels -> internal coordinates -> pixels, but which can give minor differences.
When used without a rectangle specification, the normal result of this is that the captured area is slightly different in size, and that becomes a problem for writing video frames, as videos expect constant size.
The work-around I developed a couple of months ago was to record the size of the first getframe() and thereafter imresize() whatever was captured to that size.
I have not experimented using the rectangle specification; I would think that it could result in pixels being chopped, and I do not know what would happen for the case where the size available for capture was smaller than the rectangle specification.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2017년 3월 14일
The easiest way would probably to use
axis off
followed by saveas() or print()
  댓글 수: 2
John Wray
John Wray 2017년 3월 14일
Yes, this would hide the axis, but the blank borader is still included in the saved file.
Andrea Manconi
Andrea Manconi 2019년 9월 30일
axis off tight
This should make the trick!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by