Skip to main content

Decoding images files with JAI

12 replies [Last post]
koyt
Offline
Joined: 2008-02-01

Hi,
I'm new on JAI.
I have a set of pictures that I want to display. The files are from different types (bmp, gi, tiff, jpg) and the type is unknown at each time since these file are encoded.

1- How can get the type of the file when accessing its properties, so that I can use the right decoder (ImageDecoder) to read it?
2- How to display them : Which class is better if I want to serialize the file on a distributed system? ImageRenderer or what else?
2- Is there any java API better and easy to use than JAI?

Thanks in advance

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Andrey Kuznetsov

Hi koyt,

I use following class to display images:

/**
* @author Andrey Kuznetsov
*/
public class ImagePanel extends JPanel {

Image image;

public ImagePanel(Image image) {
this.image = image;
}

public void paintComponent(Graphics g) {
super.paintComponent(g);
if (image != null) {
Insets insets = getInsets();
g.drawImage(image, insets.left, insets.top, this);
}
}

public Dimension getPreferredSize() {
Insets insets = getInsets();
if (image != null) {
return new Dimension(image.getWidth(this) + insets.left +
insets.left, image.getHeight(this) + insets.top + insets.bottom);
}
else {
return super.getPreferredSize();
}
}

public static void show(Image img, String title) {
JFrame frame = new JFrame(title);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
ImagePanel ip = new ImagePanel(img);
frame.getContentPane().add(new JScrollPane(ip));
frame.setSize(200, 300);
frame.show();
}

public static void main(String[] args) throws IOException {
String s = "
";
File f = new File(s);

Image img;
boolean useImageIO = true;

if(useImageIO) {
//with ImageIO
img = ImageIO.read(f);
}
else {
//with Imagero
ImageProcOptions options = new ImageProcOptions();
options.setSource(f);
img = Imagero.readImage(options);
}
//show image
ImagePanel.show(img, f.getName());
}
}

jai-interest@javadesktop.org schrieb:
> Hi,
> You'll see below some specimen of the files I received and that I wanted to display preferably in a JPanel.
> I just want to display these images with any java library you know. I try without success JAI, ImageIO and Imagero.
> This is the link that reach to the files :
> http://www.developpez.net/forums/attachment.php?attachmentid=25543&d=120...
>
> Thanks in advance
> [Message sent by forum member 'koyt' (koyt)]
>
> http://forums.java.net/jive/thread.jspa?messageID=258802
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

koyt
Offline
Joined: 2008-02-01

Thanks for the quick reply.

About the work itself : I work on displaying a set of pictures that are received from another one. I'm supposed to read all types of image files I receive, but their type is unknown at the begining.
I then read the files on a server and I send them through the network (an EJB is used for this job) to another server for displaying on a client desktop.

It's true that files are automatically read. But it seems like it's not the right decoder that are used, sinced when you try to access them, you an error.
So I really need to load the file and get its properties so that I can choose the right decoder. It seems difficult since I don't know what offsets are used in-memory to make a difference between files.

ImageSerialisable is an user-class I made on SerialisableRenderedImage.

Thanks

[b]PS :[/b]
that's an overview of the source I use now:
[i]java.util.List list= new ArrayList();
for ( int i = 0; i < cheminFicher.length; i++)
{
SeekableStream img = new FileSeekableStream(cheminFicher);
RenderedImage renderImage = JAI.create("stream",img);
list.add(new ImageSerialisable(signatureDelta));
}[/i]

bpb
Offline
Joined: 2004-06-23

> It's true that files are automatically read. But it
> seems like it's not the right decoder that are used,
> sinced when you try to access them, you an error.

What error?

> So I really need to load the file and get its
> properties so that I can choose the right decoder.

That should absolutely not be necessary.

> It
> seems difficult since I don't know what offsets are
> used in-memory to make a difference between files.
>
> ImageSerialisable is an user-class I made on

Version francaise. ;-)

> SerialisableRenderedImage.

But with a "z" (as in "zee," not "zed"). ;-)

>
> Thanks
>
> [b]PS :[/b]
> that's an overview of the source I use now:
> [i]java.util.List list= new ArrayList();
> for ( int i = 0; i < cheminFicher.length; i++)
> {
> SeekableStream img = new
> FileSeekableStream(cheminFicher);
> RenderedImage renderImage =
> JAI.create("stream",img);

You could just as easily use the Java Image I/O Framework (javax.imageio) here or the "ImageRead" operation provided in Image I/O Tools (https://jai-imageio.dev.java.net) either of which would be preferred.

Brian

> list.add(new ImageSerialisable(signatureDelta));
> }[/i]

koyt
Offline
Joined: 2008-02-01

Hi,
You'll see below some specimen of the files I received and that I wanted to display preferably in a JPanel.
I just want to display these images with any java library you know. I try without success JAI, ImageIO and Imagero.
This is the link that reach to the files :
http://www.developpez.net/forums/attachment.php?attachmentid=25543&d=120...

Thanks in advance

bpb
Offline
Joined: 2004-06-23

When I try to open that URL I get:

"Vous n'êtes pas connecté ou vous n'avez la permission d'accéder à cette page. Ceci est peut-être dû à une ou plusieurs raisons :"

Yes, I can understand it ...

> Hi,
> You'll see below some specimen of the files I
> received and that I wanted to display preferably in a
> JPanel.
> I just want to display these images with any java
> library you know. I try without success JAI, ImageIO
> and Imagero.
> This is the link that reach to the files :
> http://www.developpez.net/forums/attachment.php?attach
> mentid=25543&d=1202926134
>
> Thanks in advance

Brian Burkhalter

On Fri, 1 Feb 2008, jai-interest@javadesktop.org wrote:

> Hi,
> I'm new on JAI.
> I have a set of pictures that I want to display. The files are from different types (bmp, gi, tiff, jpg) and the type is unknown at each time since these file are encoded.
>
> 1- How can get the type of the file when accessing its properties, so that I can use the right decoder (ImageDecoder) to read it?

The type may be automatically detected.

> 2- How to display them : Which class is better if I want to serialize the file on a distributed system? ImageRenderer or what else?

Try SerializableRenderedImage. More details of what you are trying to do would
help.

> 2- Is there any java API better and easy to use than JAI?
^3

For image input and output we recommend the Java Image I/O Framework
(javax.image) built into Java SE and the JAI Image I/O Tools plugins
(https://jai-imageio.dev.java.net.

Brian

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

koyt
Offline
Joined: 2008-02-01

Thanks for the quick reply.

About the work itself : I work on displaying a set of pictures that are received from another one. I'm supposed to read all types of image files I receive, but their type is unknown at the begining.
I then read the files on a server and I send them through the network (an EJB is used for this job) to another server for displaying on a client desktop.

that's an overview of the source I use now:

[b][i]java.util.List list= new ArrayList();
for ( int i = 0; i < cheminFicher.length; i++) //parcours des fichiers 1 à 1 afin de les ouvrir et copier les données
{
SeekableStream img = new FileSeekableStream(cheminFicher);
RenderedImage renderImage = JAI.create("stream",img);
list.add(new ImageSerialisable(signatureDelta));
}[/i][/b]

It's true that files are automatically read. But it seems like it's not the right decoder that are used, sinced when you try to access them, you an error.
So I really need to load the file and get its properties so that I can choose the right decoder. It seems difficult since I don't know what offsets are used in-memory to make a difference between files.

ImageSerialisable is an user-class I made on SerialisableRenderedImage.

Thanks

Fork Labs

Hello koyt,

As Brian said, usually the image type is auto-detected and is
suggestion to use ImageIO can be summarized by this methods and its
siblings :

http://java.sun.com/j2se/1.4.2/docs/api/javax/imageio/ImageIO.html#read(java.io.File)

It is my limited experience that serialized object are bloated (I once
serialized a simple ParameterBlock and it took several Kb, I just
don't want to image how big a serialized image is - or why one would
want to serialize an image), why send the image serialized and not as
is ?

Regards,

Daniel Léonard

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Rafael Santos

I'd like to bump this message.

...
> It is my limited experience that serialized object are bloated (I once
> serialized a simple ParameterBlock and it took several Kb, I just
> don't want to image how big a serialized image is - or why one would
> want to serialize an image), why send the image serialized and not as
> is ?
>

Or why store serialized images or blobs in a database at all? Is there
any advantage at all of doing this?
I had a lively(*) discussion with a colleague last week who insists in
putting everything in a database, including a whole bunch of FITS and
JPEG images, and couldn't be convinced of the advantages.

Rafael

(*) biff! pow! zing!

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Brian Burkhalter

Wouldn't the storage requirements swamp the database performance eventually?

Also, what if one later wanted to use the images without the database?

On Wed, 6 Feb 2008, Rafael Santos wrote:

> I'd like to bump this message.
>
> ...
>> It is my limited experience that serialized object are bloated (I once
>> serialized a simple ParameterBlock and it took several Kb, I just
>> don't want to image how big a serialized image is - or why one would
>> want to serialize an image), why send the image serialized and not as
>> is ?
>>
>
> Or why store serialized images or blobs in a database at all? Is there any
> advantage at all of doing this?
> I had a lively(*) discussion with a colleague last week who insists in
> putting everything in a database, including a whole bunch of FITS and JPEG
> images, and couldn't be convinced of the advantages.

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Rafael Santos

> Wouldn't the storage requirements swamp the database performance
> eventually?
> Also, what if one later wanted to use the images without the database?
Some people working in a small project here want to store a huge image
breaking it in small tiles and retrieving them from a database using
"novel spatial indexing methods". I've argued that they can store the
tiles' filenames in the database and retrieve the tiles as files to make
their mosaics or whatever they want to do with it, but they want to
serialize/blobify/store the whole thing.

Well, they have a brand new database license and probably want to
explore it. It *could* be interesting to see how the whole thing
performs but I am under the impression that I shouldn't get involved :-)

Rafael

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Brian Burkhalter

On Wed, 6 Feb 2008, Rafael Santos wrote:

>
>> Wouldn't the storage requirements swamp the database performance
>> eventually?
>> Also, what if one later wanted to use the images without the database?
> Some people working in a small project here want to store a huge image
> breaking it in small tiles and retrieving them from a database using "novel
> spatial indexing methods". I've argued that they can store the tiles'
> filenames in the database and retrieve the tiles as files to make their
> mosaics or whatever they want to do with it, but they want to
> serialize/blobify/store the whole thing.
> Well, they have a brand new database license and probably want to explore it.
> It *could* be interesting to see how the whole thing performs but I am under
> the impression that I shouldn't get involved :-)

Sounds weird. My first impulse would be to store a reference to the entire
file in some tiled format and use two indirections. But what do I know?

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net