This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

im2java2d

Convert image to Java buffered image

Syntax

javaImage = im2java2d(I)
javaImage = im2java2d(X,map)

Description

example

javaImage = im2java2d(I) converts the input image to an instance of the Java image class java.awt.image.BufferedImage.

example

javaImage = im2java2d(X,map) converts an indexed image with colormap map to an instance of the Java image class java.awt.image.BufferedImage.

Examples

collapse all

Read an input image into the workspace.

I = imread('cameraman.tif');

Convert the input image to a Java buffered image.

javaImage = im2java2d(I);

Create an icon from the java buffered image.

icon = javax.swing.ImageIcon(javaImage);

Create a label to display the image icon.

label = javax.swing.JLabel(icon);

Read the size of the label and the set the location and size of the drawable area in figure window.

pSize = label.getPreferredSize;
f = figure('visible','off');
fPos = get(f,'Position');
fPos(3:4) = [pSize.width, pSize.height];
set(f,'Position',fPos);

Display the Java component label at the specified position in figure window.

hLabel = javacomponent(label,[0 0 fPos(3:4)],f);
figure(f)

Read an indexed image into the workspace.

load mandrill

Display the indexed image X using its associated colormap, map.

figure
imshow(X,map)

Convert the input indexed image to a Java buffered image.

javaImage = im2java2d(X,map);

Create an icon from the java buffered image.

icon = javax.swing.ImageIcon(javaImage);

Create a label to display the image icon.

label = javax.swing.JLabel(icon);

Read the size of the label and the set the location and size of the drawable area in figure window.

pSize = label.getPreferredSize;
f = figure('visible','off');
fPos = get(f,'Position');
fPos(3:4) = [pSize.width, pSize.height];
set(f,'Position',fPos);

Display the Java component label at the specified position in figure window.

hLabel = javacomponent(label,[0 0 fPos(3:4)],f);
figure(f)

Input Arguments

collapse all

Input image, specified as

  • m-by-n matrix for grayscale and binary images.

  • m-by-n-by-3 matrix for RGB color images.

Data Types: double | uint8 | uint16 | logical

Input indexed image, specified as a m-by-n matrix.

Data Types: double | uint8 | uint16

Colormap associated with input indexed image X, specified as a c-by-3 numeric array. c represents the number of colors in the colormap.

Data Types: double

Output Arguments

collapse all

Output Java 2D image, returned as a BufferedImageclass of instance java.awt.image.BufferedImage. The output Java 2D image can be used with the Java 2D API and the Java Abstract Windowing Toolkit (AWT).

Introduced before R2006a