Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    BrooksyFC is offline Member
    Join Date
    Mar 2012
    Posts
    20
    Rep Power
    0

    Question Open TIFF File With Java

    Hey Guys, I'm new to Java and I've got a task in work that I'm not sure how to go about.

    Basically, I've got a TIFF file that I need to open in Java, but I haven't got a clue how to do it. I've googled it and I've been taken to Java websites and forums but I'm still really stuck.

    I've done some php before but never used java so if someone could help with and guide me through I would really appreciate it

    Thanks,
    Ryan

  2. #2
    gauravfzd's Avatar
    gauravfzd is offline Member
    Join Date
    Oct 2010
    Location
    India
    Posts
    72
    Rep Power
    0

    Default Re: Open TIFF File With Java

    I Guess TIFF images are supported by Java. If it is the Create a Gui using Swing Framework, add a JLabel to it.

    Create a ImageIcon as

    ImageIcon image = new ImageIcon("location to Image");
    label.setIcon(image);


    If you don't know Swing or AWT or SWT or Javafx, then Sorry I don't know......

  3. #3
    BrooksyFC is offline Member
    Join Date
    Mar 2012
    Posts
    20
    Rep Power
    0

    Default Re: Open TIFF File With Java

    Thanks for the reply, I'm not really sure to be fair :P I've littereally just told to "read a tiff file in Java" I don't know anything about Swing e.t.c

  4. #4
    gauravfzd's Avatar
    gauravfzd is offline Member
    Join Date
    Oct 2010
    Location
    India
    Posts
    72
    Rep Power
    0

    Default Re: Open TIFF File With Java

    Learning Swing is easy, Look for tutorials and examples on the internet.....

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Open TIFF File With Java

    What are you going to do with the data in the file?
    That requirement is pretty open.
    You could simply open a stream to the file and read the individual bytes in.
    So what are you trying to achieve by "read TIFF file"?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    BrooksyFC is offline Member
    Join Date
    Mar 2012
    Posts
    20
    Rep Power
    0

    Default Re: Open TIFF File With Java

    Once I'm able to read the tiff file, I would like to be able to read part of the image, like a pacific location to it.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Open TIFF File With Java

    Then read it into a BufferedImage.
    You can then read and manipulate the image in Java.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    BrooksyFC is offline Member
    Join Date
    Mar 2012
    Posts
    20
    Rep Power
    0

    Default Re: Open TIFF File With Java

    Ok Ill give it a look.

    I found this bunch of code here, but I'm confused on what I actually do with it.

    Converting Images to BufferedImages [java] [image]

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Open TIFF File With Java

    Not sure about that lot
    ImageIO is a class that has several read() methods, which return BufferedImages.
    That's what you need.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    BrooksyFC is offline Member
    Join Date
    Mar 2012
    Posts
    20
    Rep Power
    0

    Default Re: Open TIFF File With Java

    I've seen ImageIO mentioned about. Do I need to download something? If so where do I install the files to?

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Open TIFF File With Java

    It's part of the standard Java libraries, so no installation or extra jar files needed.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    BrooksyFC is offline Member
    Join Date
    Mar 2012
    Posts
    20
    Rep Power
    0

    Default Re: Open TIFF File With Java

    Ok cool. That's easy enough,

    So with this code here for example: A Java program to open, read, and display an image file | devdaily.com, would I just simply copy this, change the file name and save it as a .java file? I'm not too sure what I'm doing here

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Open TIFF File With Java

    Well, first off I'd learn Java.
    Mucking about with images and Swing if you don't know the basics (and that really seems to be the case here) is not likely to end happily.
    Here's the general tutorials.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #14
    BrooksyFC is offline Member
    Join Date
    Mar 2012
    Posts
    20
    Rep Power
    0

    Default Re: Open TIFF File With Java

    I've been though the tutorials.

    I'm using this code now:

    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;

    public class LoadAndShow extends JPanel {
    BufferedImage image;
    Dimension size = new Dimension();

    public LoadAndShow(BufferedImage image) {
    this.image = image;
    size.setSize(image.getWidth(), image.getHeight());
    }

    /**
    * Drawing an image can allow for more
    * flexibility in processing/editing.
    */
    protected void paintComponent(Graphics g) {
    // Center image in this component.
    int x = (getWidth() - size.width)/2;
    int y = (getHeight() - size.height)/2;
    g.drawImage(image, x, y, this);
    }

    public Dimension getPreferredSize() { return size; }

    public static void main(String[] args) throws IOException {
    String path = "pictures/Snow.jpg";
    BufferedImage image = ImageIO.read(new File(path));
    LoadAndShow test = new LoadAndShow(image);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new JScrollPane(test));
    f.setSize(400,400);
    f.setLocation(200,200);
    f.setVisible(true);
    //showIcon(image);
    }

    /**
    * Easy way to show an image: load it into a JLabel
    * and add the label to a container in your gui.
    */
    private static void showIcon(BufferedImage image) {
    ImageIcon icon = new ImageIcon(image);
    JLabel label = new JLabel(icon, JLabel.CENTER);
    JOptionPane.showMessageDialog(null, label, "icon", -1);
    }
    }
    but I keep getting this error back:

    error: class LoadAndShow is public, should be declared in a file named LoadAndShow.java
    public class LoadAndShow extends JPanel {

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Open TIFF File With Java

    Which is part of the basics.
    All public Java class source code should be in a file with the same name as the class name.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #16
    BrooksyFC is offline Member
    Join Date
    Mar 2012
    Posts
    20
    Rep Power
    0

    Default Re: Open TIFF File With Java

    One things I might be missing, which I keep hearing about, is JAI. I've found the download, but where do I install it to? Is there a folder in Netbeans I need to put it in?

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Open TIFF File With Java

    Why do you think you need that?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    BrooksyFC is offline Member
    Join Date
    Mar 2012
    Posts
    20
    Rep Power
    0

    Default Re: Open TIFF File With Java

    I'm not sure, I think cause it supports TIFF files. I want to try and get a .jpg being read first just so I can get something working, all I keep getting is errors

  19. #19
    BrooksyFC is offline Member
    Join Date
    Mar 2012
    Posts
    20
    Rep Power
    0

    Default Re: Open TIFF File With Java

    error: class ReadingImage is public
    This error comes up all the time

  20. #20
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Open TIFF File With Java

    You've been told already, learn the basics first. You have to learn to walk before you try to run.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Page 1 of 2 12 LastLast

Similar Threads

  1. Java save to file / open from file - trouble
    By joelBeaton in forum Advanced Java
    Replies: 6
    Last Post: 03-23-2012, 12:47 PM
  2. How to open an .odf file in java
    By deshmukh.niraj04 in forum New To Java
    Replies: 11
    Last Post: 03-17-2011, 01:51 PM
  3. Replies: 0
    Last Post: 11-03-2009, 11:36 AM
  4. Different Files Open in File -> Open Workspace
    By mgm2010 in forum JCreator
    Replies: 0
    Last Post: 04-11-2009, 02:14 PM
  5. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 09:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •