Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2004

Tip: Looking for answers? Try searching our database.

How to open and display a TIFF file?

Thread view: 
Ramon - 21 Dec 2004 15:32 GMT
Hello again:

I need some guidance on the details of opening a TIFF
file and displaying it, using Swing.

Need more details?

What I am trying to implement here is a super-simplified
version of Acrobat Professional's function where it allows
you to draw widgets (text fields, radio buttons, etc.) on
top of an underlying TIFF file.  The big difference with
Adobe's tool is that my program will generate source code
to add those fields to a PDF file.

In a related posting, I am also looking for source code
to implement the rubbberband technique.

TIA,

-Ramon F Herrera
Ramon - 21 Dec 2004 16:14 GMT
After I posted the above, I discovered something called
"JAI" (Java Advanced Imaging).  So is this the recommended
way to open and display a TIFF file?

It's just that I hardly think of opening and displaying a TIFF
as "advanced".
Is JAI an overkill or is it the right tool?

TIA,

-Ramon
Andrei Kouznetsov - 21 Dec 2004 17:38 GMT
> After I posted the above, I discovered something called
> "JAI" (Java Advanced Imaging).  So is this the recommended
[quoted text clipped - 3 lines]
> as "advanced".
> Is JAI an overkill or is it the right tool?

JAI is ok, but JAI's destination is a bit other (medical imaging, HUGE
images, satellite images...).
JAI is may be too heawyweight for you.
However you don't need JAI for just image loading.
You can use ImageIO or ImageroReader (http://reader.imagero.com) (works also
with java 1.1)

You can find more info here
http://www.geocities.com/marcoschmidt.geo/java-image-coding.html

Signature

Andrei Kouznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Keith James - 21 Dec 2004 18:31 GMT
>>>>> "Ramon" == Ramon  <ramon@conexus.net> writes:

   Ramon> After I posted the above, I discovered something called
   Ramon> "JAI" (Java Advanced Imaging).  So is this the recommended
   Ramon> way to open and display a TIFF file?

   Ramon> It's just that I hardly think of opening and displaying a
   Ramon> TIFF as "advanced".  Is JAI an overkill or is it the right
   Ramon> tool?

I can't comment on whether JAI is overkill for your requirements -
that would need more information. However, I can say that we've used
javax.imageio.ImageIO with the TIFF plugin quite successfully. It's
very simple - one method call to go between BufferedImages and TIFF
files (or vice versa).

You'll need the Image I/O API from

http://java.sun.com/products/java-media/jai/current.html

Put the jar file(s) on the CLASSPATH and the ImageIO.read methods will
return BufferedImages from TIFF files.

We've used it with 8- and 16-bpp TIFFs. Some software out there may
produce TIFFs which don't conform to the spec e.g. 12-bpp (so the
pixel data doesn't align with byte boundaries). The plugin won't work
with such files.

Signature

- Keith James <kdj@sanger.ac.uk> Microarray Facility, Team 65 -
- The Wellcome Trust Sanger Institute, Hinxton, Cambridge, UK -

Ramon - 21 Dec 2004 21:14 GMT
> I can't comment on whether JAI is overkill for your requirements -
> that would need more information.

Well, my app needs to open just one file at a time.  It is a
standard TIFF, non-compressed, black&white, 600 dpi image of
an 8.5x11 inchpage. It comes from an HP scanner.  The image is
read-only and used only to guide the user on what are the precise
spots where s/he wants some widgets to be added to a future PDF
version of the TIFF file.

Thanks,

-Ramon
Ramon - 21 Dec 2004 22:17 GMT
> However, I can say that we've used javax.imageio.ImageIO
> with the TIFF plugin quite successfully.

The above seems to imply that Keith has used those tools in an
applet.  I am not writing an applet, I am writing an application.

Can I still use the javax.imageio.ImageIO in an application?
Thanks,

-Ramon
Keith James - 22 Dec 2004 11:37 GMT
>>>>> "Ramon" == Ramon  <ramon@conexus.net> writes:

   >> However, I can say that we've used javax.imageio.ImageIO with
   >> the TIFF plugin quite successfully.

   Ramon> The above seems to imply that Keith has used those tools in
   Ramon> an applet.  I am not writing an applet, I am writing an
   Ramon> application.

I'm not sure what makes you say this, but in fact we are using this
API in a Swing application. We use only the I/O jar file because it
provides a TIFF encoder/decoder plugin for ImageIO. The TIFF image is
displayed in the application by using a BufferedImage to paint the
background of a JPanel subclass in the normal way, by overriding
paintComponent.

   Ramon> Can I still use the javax.imageio.ImageIO in an
   Ramon> application?

Yes. To answer your other point on whether you need the full JAI
package - provided that you only wish to read and display single
images you could use only the I/O component. The complete kit provides
lots of image manipulation operators which you probably won't need.

Signature

- Keith James <kdj@sanger.ac.uk> Microarray Facility, Team 65 -
- The Wellcome Trust Sanger Institute, Hinxton, Cambridge, UK -

Ramon - 22 Dec 2004 16:15 GMT
Ramon> The above seems to imply that Keith has used those tools in
Ramon> an applet.
Keith> I'm not sure what makes you say this, but in fact we are
Keith> using this API in a Swing application.

It was the word "plugin".  I incorrectly assumed that it was
a reference to the plugins that become part of Netscape or IE.
After looking deeper into the JAI, I realize now that in that
context there are other types of plugins.

-Ramon
Ramon - 22 Dec 2004 16:57 GMT
Andrei> JAI may be too heawyweight for you.
Andrei> You don't need JAI for just image loading.

Keith> To answer your other point on whether you need the
Keith> full JAI package - provided that you only wish to read and
Keith> display single images you could use only the I/O component.
Keith> The complete kit provides lots of image manipulation operators
Keith> which you probably won't need.

This brings us to the next point I would like to address:
the image size.

All my images are pages that were scanned at 600 dpi.  I recently
realized that the concept of "DPI" is not too transportable.  A
TIFF file simply says: "I am 5100 pixels wide by 6600 pixels tall"
and it is up to the output device to decide how many DPIs to use.
Now I have huge images because the software must have assumed
72 dpi.

How can I reduce those images to a more reasonable size?
Is the some sort of built-in switch (in ImageIO or in the full JAI)
to specify the desired DPIs of the displayed image?

Or will I have to resort to some transformation such as the one
at the botton of this page:

http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/inde
x.html

Thanks again,

-Ramon
Keith James - 22 Dec 2004 20:34 GMT
[...]

   Ramon> How can I reduce those images to a more reasonable size?
   Ramon> Is the some sort of built-in switch (in ImageIO or in the
   Ramon> full JAI) to specify the desired DPIs of the displayed
   Ramon> image?

   Ramon> Or will I have to resort to some transformation

One way is to use the standard Java2D transforms. Something like the
following assuming we are drawing into a JComponent

   protected void paintComponent(Graphics g)
   {
       super.paintComponent(g);

       Graphics2D g2 = (Graphics2D) g.create();

       AffineTransform transform = new AffineTransform();

       // Translate so we don't draw in the component's borders
       Insets insets = getInsets();
       transform.translate(insets.left, insets.top);

       // Scale accessors return doubles indicating scale factor
       // on each axis
       transform.scale(getXScale(), getYScale());

       g2.transform(transform);

       // Accessor returns the image created from the TIFF file
       Image image = getImage();
       if (null != image)
       {
           g2.drawImage(image, 0, 0, this);
       }

       // As we created a new Graphics2D above we must free
       // any system resources
       g2.dispose();
   }

I guess in your case you won't want a different scale on each axis,
otherwise the aspect ratio of the image will change.

What I do in our application is allow the user to control the scale
interactively with a JSlider so that they can make the image a size
which is comfortable to view.

Signature

- Keith James <kdj@sanger.ac.uk> Microarray Facility, Team 65 -
- The Wellcome Trust Sanger Institute, Hinxton, Cambridge, UK -



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.