function saveDisplay(hObject)
%SAVEDISPLAY saves the current display in a file
% SAVEDISPLAY(HOBJECT) takes any object in the BM gui as an argument. It
% requests a file name from the user then saves the current bitmap
% display in the file using imwrite. Assumes the bitmap is switched on,
% so its CData is valid.
% Copyright 2008 University of Sussex and David Young
handles = guidata(hObject);
% Get possible image formats into right structure for uiputfile
fmts = imformats;
fmtcells = cell(length(fmts), 2);
for i = 1:length(fmts)
exts = fmts(i).ext;
f = ['*.' exts{1}];
% Might be better to have a separate entry for each extension?
for j = 2:length(exts)
f = [f ';*.' exts{j}];
end
fmtcells{i, 1} = f;
fmtcells{i, 2} = fmts(i).description;
end
ud = get(hObject, 'UserData');
[filename, pathname] = uiputfile(fmtcells, 'Save display as', ud.file);
if ~isequal(filename, 0) && ~isequal(pathname, 0)
file = fullfile(pathname, filename);
ud.file = file;
set(hObject, 'UserData', ud);
im = get(handles.bitmapDisplay.image, 'CData');
map = handles.bitmapDisplay.colourmap;
% resize image here to avoid using toolbox
scale = 4;
sz = size(im);
bigarr = repmat((im(:))', scale, 1);
bigarr = reshape(bigarr, scale*sz(1), sz(2));
bigarr = bigarr';
bigarr = repmat((bigarr(:))', scale, 1);
bigarr = reshape(bigarr, scale*sz);
bigarr = bigarr';
imwrite(bigarr, map, fullfile(pathname, filename));
end
end