主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

使用 Java 渲染 MATLAB 图像数据

本节包含用于演示处理图形和图像数据相关的特定功能的代码片段。

使用图像

从组件中的图像获取编码图像字节

public byte[] getByteArrayFromDeployedComponent()
{
    Object[] byteImageOutput = null;
    MWNumericArray numericImageByteArray = null;
    try
    {
        byteImageOutput =
            deployment.getImageDataOrientation(
                1,      //Number Of Outputs    
                500,    //Height
                500,    //Width
                30,     //Elevation
                30,     //Rotation
                "png"   //Image Format
            );
        
        numericImageByteArray = 
              (MWNumericArray)byteImageOutput[0];
        return numericImageByteArray.getByteData();
    }
    finally
    {
        MWArray.disposeArray(byteImageOutput);
    }
}

获取组件中的缓冲图像

public byte[] getByteArrayFromDeployedComponent()
{
    Object[] byteImageOutput = null;
    MWNumericArray numericImageByteArray = null;
    try
    {
        byteImageOutput =
            deployment.getImageDataOrientation(
                1,      //Number Of Outputs    
                500,    //Height
                500,    //Width
                30,     //Elevation
                30,     //Rotation
                "png"   //Image Format
            );
        
        numericImageByteArray = 
                 (MWNumericArray)byteImageOutput[0];
        return numericImageByteArray.getByteData();
    }
    finally
    {
        MWArray.disposeArray(byteImageOutput);
    }
}

public BufferedImage getBufferedImageFromDeployedComponent()
{
    try
    {
        byte[] imageByteArray = 
               getByteArrayFromDeployedComponent()
        return ImageIO.read
                (new ByteArrayInputStream(imageByteArray));
    }
    catch(IOException io_ex)
    {
        io_ex.printStackTrace();
    }
}

MATLAB 数组创建缓冲图像

使用 renderArrayData 方法可以:

  • 根据给定 MATLAB® 数组中的数据创建缓冲图像。

  • 验证数组是否具有三个维度(高度、宽度和颜色组件)。

  • 验证颜色组件顺序为红色、绿色和蓝色。

    有关输入参数、返回值、抛出的异常和示例的信息,请参阅 Java® API 文档中的 renderArrayData

另请参阅

主题