00001 package dataToImage;
00002
00003 import java.awt.GraphicsConfiguration;
00004 import java.awt.GraphicsDevice;
00005 import java.awt.GraphicsEnvironment;
00006 import java.awt.Image;
00007 import java.awt.image.BufferedImage;
00008 import java.awt.image.WritableRaster;
00009 import java.io.File;
00010 import java.io.IOException;
00011 import java.io.PrintStream;
00012
00013 import javax.imageio.ImageIO;
00014
00015 import com.sun.media.sound.Toolkit;
00016
00017 import debuggingCode.Debug;
00018
00023 public class GrayImage {
00024
00025 BufferedImage image;
00026
00027 WritableRaster raster;
00028
00032 public GrayImage(int width, int height) {
00033
00034
00035 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
00036 GraphicsDevice gs = ge.getDefaultScreenDevice();
00037 GraphicsConfiguration gc = gs.getDefaultConfiguration();
00038
00039
00040
00041
00042 image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
00043
00044 raster = image.getRaster();
00045
00046 }
00047
00048 public void setSample(int x, int y, int grijswaarde) {
00049
00050
00051
00052 if(grijswaarde<0 || grijswaarde>255){
00053 if(!Debug.DISTIBUTION) Debug.print("grijswaarde " + grijswaarde);
00054 grijswaarde=0;
00055 Object o=null;
00056
00057
00058 }
00059
00060
00061
00062
00063 raster.setSample(x, y, 0, grijswaarde);
00064 }
00065
00066
00067 public BufferedImage getBufferedImage(){
00068 return this.image;
00069 }
00070
00071 public Image getImage() {
00072 return java.awt.Toolkit.getDefaultToolkit().createImage(image.getSource());
00073 }
00074
00075 public void writePNG(File toFile) throws IOException {
00076
00077 ImageIO.write(image, "PNG", toFile);
00078
00079 }
00080
00081 public void print(PrintStream p){
00082 for(int x=0;x!=raster.getWidth();x++){
00083 for(int y=0;y!=raster.getHeight();y++){
00084 p.print(raster.getSample(x,y,0)+ " ");
00085 }
00086 p.println("");
00087 }
00088
00089 }
00090
00091 }