打算弄下图形处理 结果把图像转换为 int数组之后不论怎么弄都无法还原了 希望哪位大哥处理下 下面是代码:
public class DemoPanel extends JFrame {
public DemoPanel() {
init();
}
BufferedImage im ;
Image im2;
public void init() {
try {
im = ImageIO.read(new File("E:/lc/MyPictures/g.jpg"));
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
int w = im.getHeight(null);
int h = im.getWidth(null);
int[] pix = new int[w * h];
try {
PixelGrabber pg = new PixelGrabber(im, 0, 0, w, h, pix, 0, w);
pg.grabPixels();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//ColorModel cm = ColorModel.getRGBdefault();
for (int x = 0; x < w * h; x++) {
System.out.println(pix[x]);
}
ImageProducer ip = new MemoryImageSource(0, 0, pix, 0, w);
im2 = java.awt.Toolkit.getDefaultToolkit().createImage(ip);
JPanel panel = new JPanel() {
protected void paintComponent(Graphics g) {
g.drawImage(im2, 0, 0, 100, 100, this);
}
};
this.add(panel);
this.setSize(w,h);
}
public static void main(String[] args) {
new DemoPanel().setVisible(true);
}
}
|