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......
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
Re: Open TIFF File With Java
Learning Swing is easy, Look for tutorials and examples on the internet.....
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"?
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.
Re: Open TIFF File With Java
Then read it into a BufferedImage.
You can then read and manipulate the image in Java.
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]
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.
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?
Re: Open TIFF File With Java
It's part of the standard Java libraries, so no installation or extra jar files needed.
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 :(-:
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.
Re: Open TIFF File With Java
I've been though the tutorials.
I'm using this code now:
Quote:
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:
Quote:
error: class LoadAndShow is public, should be declared in a file named LoadAndShow.java
public class LoadAndShow extends JPanel {
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.
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?
Re: Open TIFF File With Java
Why do you think you need that?
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
Re: Open TIFF File With Java
Quote:
error: class ReadingImage is public
This error comes up all the time
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