/**
*
* @author marcelo
*/
public class BufferedImageSeriolizable implements Serializable {
private int width;
private int height;
private int[] pixels;
public BufferedImageSeriolizable() {
}
public BufferedImageSeriolizable(File file) throws IOException{
this(ImageIO.read(file));
}
public BufferedImageSeriolizable(BufferedImage bi) {
//System.out.println("criando BufferedImageSeriolizable");
width = bi.getWidth();
height = bi.getHeight();
pixels = new int[width * height];
/*int[] tmp = */bi.getRGB(0, 0, width, height, pixels, 0, width);
}
public void setBufferedImage(BufferedImage bi){
width = bi.getWidth();
height = bi.getHeight();
pixels = new int[width * height];
bi.getRGB(0, 0, width, height, pixels, 0, width);
}
public BufferedImage getBufferedImage() {
//System.out.println("getBufferedImage");
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
bi.setRGB(0, 0, width, height, pixels, 0, width);
//System.out.println("BufferedImage: " + bi);
return bi;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int[] getPixels() {
return pixels;
}
public void setPixels(int[] pixels) {
this.pixels = pixels;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
@Override
public String toString() {
return "BufferedImageSeriolizable{" + "width=" + width + ", height=" + height + ", pixels=" + pixels + '}';
}
}