Create a figure window. For example:
h = figure;
Add graphics to the figure. For example:
surf(peaks);
Optionally, you can change the figure numerous ways. For example:
set(h, 'Visible', 'off');
set(h, 'Color', [.8,.9,1]);
width=500; height=500; rotation=30; elevation=30; set(h, 'Position', [0, 0, width, height]); view([rotation, elevation]);
Export the contents of the figure in one of two ways:
To export as a WebFigure:
returnFigure = webfigure(h);
To export image data, for example:
imgform = 'png'; returnByteArray = figToImStream(`figHandle', h, ... `imageFormat', imgform, ... `outputType', `uint8');
To close the figure window:
close(h);
function returnFigure = getWebFigure() h = figure; set(h, 'Visible', 'off'); surf(peaks); set(h, 'Color', [.8,.9,1]); returnFigure = webfigure(h); close(h);
function returnByteArray = getImageDataOrientation(height, width, elevation, rotation, imageFormat ) h = figure; set(h, 'Visible', 'off'); surf(peaks); set(h, 'Color', [.8,.9,1]); set(h, 'Position', [0, 0, width, height]); view([rotation, elevation]); returnByteArray = figToImStream(`figHandle', h, ... `imageFormat', imageFormat, ... `outputType', `uint8'); close(h);
function returnByteArray = getImageDataOrientation(height, width, elevation, rotation, imageFormat ) h = figure; set(h, 'Visible', 'off'); surf(peaks); set(h, 'Color', [.8,.9,1]); set(h, 'Position', [0, 0, width, height]); view([rotation, elevation]); returnByteArray = figToImStream(`figHandle', h, ... `imageFormat', imageFormat, ... `outputType', `int8'); close(h);