Main Content

figToImStream

Stream figure as byte array encoded in specified format

Description

output = figToImStream creates a signed byte array with the PNG data for the current figure.

example

output = figToImStream (Name,Value) creates a byte array with the image data for the specified figure. You can specify the encoding format for the image and whether the byte array is signed or unsigned.

example

Examples

Convert current figure to a signed PNG formatted byte array

surf(peaks)
bytes = figToImStream

Convert a specific figure to a PNG stored in an unsigned byte array

f = figure;
surf(peaks);
bytes = figToImStream('figHandle',f,...
                      'imageFormat','bmp',...
                      'outputType','uint8');

Input Arguments

collapse all

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'figHandle', f, 'imageFormat', 'bmp', 'outputType', 'uint8' specifies the figure f is streamed into an unsigned byte array as a bitmap.

Figure to stream, specified as the comma-separated pair consisting of 'figHandle' and a figure handle.

Encoding format, specified as the comma-separated pair consisting of 'imageFormat' and one of these values:

  • png — encode the image using the Portable Network Graphics (PNG) format

  • jpg — encode the image using the JPEG format

  • gif — encode the image using the Graphics Interchange Format (GIF)

Type of bytes to store the image stream, specified as the comma-separated pair consisting of 'outputType' and one of these values:

  • int8 — use a signed byte array

  • uint8 — use an unsigned byte array

Output Arguments

collapse all

Encoded figure data returned as a byte array.

Version History

Introduced in R2009b