关于Java int数组还原图像

[复制链接]
查看11 | 回复1 | 2010-6-18 16:52:39 | 显示全部楼层 |阅读模式
打算弄下图形处理 结果把图像转换为 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);
}
}

回复

使用道具 举报

千问 | 2010-6-18 16:52:39 | 显示全部楼层
ImageProducer ip = new MemoryImageSource(0, 0, pix, 0, w);--》改成ImageProducer ip = new MemoryImageSource(w, h, pix, 0, w);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行