Working with MATLAB Figure
and Image Data
Front-End Web Developer
| Role | Knowledge Base | Responsibilities |
Front-end
Web developer | | As service consumer, manages presentation and usability Creates front-end applications Integrates MATLAB code with language-specific frameworks
and environments Integrates WebFigures with the rest of the Web page
|
For More Comprehensive Examples
This section contains code snippets intended to demonstrate
specific functionality related to working with figure and image data.
To see these snippets in the context of more fully-realized
multi-step examples, see the MATLAB Application Deployment Web Example Guide.
Back to Top
Working with Figures
Getting a Figure From a Deployed Component
For information about how to retrieve a figure from a deployed
component, see Working with Functions that Return a Single WebFigure as the
Function's Only Output.
Back to Top
Working with Images
Getting Encoded Image Bytes from an Image in a Component
.NET
public byte[] getByteArrayFromDeployedComponent()
{
MWArray width = 500;
MWArray height = 500;
MWArray rotation = 30;
MWArray elevation = 30;
MWArray imageFormat = "png";
MWNumericArray result =
(MWNumericArray)deployment.getImageDataOrientation(
height,
width,
elevation,
rotation,
imageFormat);
return (byte[])result.ToVector(MWArrayComponent.Real);
}
Getting a Buffered Image in a Component
.NET
public byte[] getByteArrayFromDeployedComponent()
{
MWArray width = 500;
MWArray height = 500;
MWArray rotation = 30;
MWArray elevation = 30;
MWArray imageFormat = "png";
MWNumericArray result =
(MWNumericArray)deployment.getImageDataOrientation(
height,
width,
elevation,
rotation,
imageFormat);
return (byte[])result.ToVector(MWArrayComponent.Real);
}
public Image getImageFromDeployedComponent()
{
byte[] byteArray = getByteArrayFromDeployedComponent();
MemoryStream ms = new MemoryStream(myByteArray, 0,
myByteArray.Length);
ms.Write(myByteArray, 0, myByteArray.Length);
return Image.FromStream(ms, true);
}
Getting Image Data from a WebFigure
The following example shows how to get image data from a WebFigure
object. It also shows how to specify the image type and the orientation
of the image.
.NET
WebFigure figure =
new WebFigure(deployment.getWebFigure());
WebFigureRenderer renderer =
new WebFigureRenderer();
//Creates a parameter object that can be changed
// to represent a specific WebFigure and its orientation.
//If you dont set any values it uses the defaults for that
// figure (what they were when the figure was created in M).
WebFigureRenderParameters param =
new WebFigureRenderParameters(figure);
param.Rotation = 30;
param.Elevation = 30;
param.Width = 500;
param.Height = 500;
//If you need a byte array that can be streamed out
// of a web page you can use this:
byte[] outputImageAsBytes =
renderer.RenderToEncodedBytes(param);
//If you need a .NET Image (can't be used on the web)
// you can use this code:
Image outputImageAsImage =
renderer.RenderToImage(param);
Back to Top
 | Creating and Modifying a MATLAB Figure | | .NET Remoting |  |
Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
Get the Interactive Kit