Re: Compiler warning issue
In article
<d9c1768f-0088-413f-bdf7-66be940d7be8@22g2000yqr.googlegroups.com>,
bH <bherbst65@hotmail.com> wrote:
Thanks for your responses.
Can I digress but not alter this thread of
my original post? Is JPEG the issue then what
image form is not an issue? Or is it not an issue,
but what is done to the image form namely
cutting a jpeg image into 16 images from the
original image. Or is it something entirely
different?
By all means. Your program is an excellent example of what Lew
elaborated: Don't settle for spurious warnings. You can entirely
eliminate the warning, and the dependence on Sun's proprietary codec,
by using the published API. Here's my variation:
package news;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ImageOnLabelFrame extends JFrame {
BufferedImage bi = null;
List<JLabel> list = new ArrayList<JLabel>();
ImageOnLabelFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
init();
setVisible(true);
}
public void init() {
try {
bi = ImageIO.read(new File("image.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
setLayout(new GridLayout(4, 4));
int c = 0;
if (bi == null) return;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
int w = bi.getWidth() / 4;
int h = bi.getHeight() / 4;
BufferedImage b = bi.getSubimage(i * w, j * h, w, h);
list.add(new JLabel(new ImageIcon(b)));
try {
String name = "temp" + Integer.toString(c) + ".jpg";
ImageIO.write(b, "jpeg", new File(name));
c++;
} catch (IOException e) {
e.printStackTrace();
}
}
}
Collections.shuffle(list);
for (JLabel l : list) add(l);
pack();
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new ImageOnLabelFrame();
}
});
}
}
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>