-
Notifications
You must be signed in to change notification settings - Fork 1
/
clipclipimage.m
63 lines (52 loc) · 1.72 KB
/
clipclipimage.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function clipclipimage(axH)
%CLIPCLIPIMAGE (tools): copy image in current axes to a file
%
% This is different from CLIPCLIPPIX because it saves only the image,
% not a pixel screenshot of the entire figure including labels, etc.
% Note it only saves the topmost image, not all images in the axes.
%
% See also CLIPCLIP, CLIPCLIPPIX
%
% MH - http://github.com/histed/tools-mh
if nargin < 1, axH = gca; end
%% set paths
% first file export path
%fPath = 'm:/shared/snapshots';
dirs = directories;
fPath = dirs.toolsSnapshots;
fName = [mfilename '-' datestr(now)];
fName = strrep(fName, ' ', '_');
fName = strrep(fName, ':', '-');
fullF = fullfileMH(fPath, fName);
%%% must create a new figure to make sure it's the right size during
%%% screenshot
xLim = get(axH, 'XLim');
yLim = get(axH, 'YLim');
xSize = range(xLim);
ySize = range(yLim);
% copy and remove children, leaving props intact
newFigH = copyobj(get(axH, 'Parent'), 0);
delete(get(newFigH, 'Children'));
set(newFigH, 'WindowStyle', 'modal', ...
'Units', 'pixels', ...
'Position', [0 0 xSize+100 ySize+100], ...
'Resize', 'off');
% copy axes
newAxH = copyobj(axH, newFigH);
set(newAxH, 'Units', 'pixels', ...
'Position', [50 50 xSize ySize], ...
'Box', 'off', ...
'TickDir', 'out', ...
'Selected', 'off');
% crazy bs: if any are docked, dock this one?
% $$$ aFH = findobj(0, 'Type', 'Figure', 'WindowStyle', 'docked');
% $$$ if ~isempty(aFH)
% $$$ % dock this one
% $$$ %set(newFigH, 'WindowStyle', 'docked');
% $$$ end
%% grab the frame
drawnow;
m = getframe(newAxH);
imwrite(m.cdata, [fullF '.png'], 'png');
close(newFigH);
%unix(sprintf('convert %s %s', [fullF '.png'], [fullF '.wmf']));