| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 
 | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
 
 
 
public class Lecture extends DataInputStream {
 
	private int h, w, size;
 
   public Lecture(int w, int h, String filename) throws FileNotFoundException {
		super(new FileInputStream(filename));
		this.h = h;
		this.w = w;
		this.size = h * w ;
	}
 
	public int[] readLigne() throws IOException {
		int tab[] = new int[w];
		for (int i = 0; i < w; i++) {
			tab[i] = (int)readShort();
		}
		return tab;
	}
 
}   
 
 
import java.awt.Canvas;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.ScrollPane;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.WritableRaster;
import java.io.FileNotFoundException;
import java.io.IOException;
 
import javax.swing.JPanel;
 
 
public class Essai extends Canvas {
	BufferedImage image = null;
 
 
	public Essai(int w, int h){
 
		image = new BufferedImage(w, h, BufferedImage.TYPE_USHORT_GRAY);
		WritableRaster raster = image.getRaster();
		Lecture lecture = null;
		try {
			lecture = new Lecture(w, h, "test.LJPEG.1");
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
 
 
		int[] pixels = new int[w];
		for (int j = 0; j < h; j++)
			try {
				pixels = lecture.readLigne();
				raster.setPixels(0, j, w, 1, pixels);
			} catch (IOException e) {
 
				e.printStackTrace();
			}
 
		image.setData(raster);
System.out.println("c fait");
	}
	public void paint(Graphics g) {
	g.drawImage(image, 0, 0, (ImageObserver) this);
	}
 
	public static void main(String[] args) {
 
Frame frame = new Frame("frame");
 
      ScrollPane p = new ScrollPane();
		p.add(new Essai(3721, 1681));
 
		frame.add(p);
		frame.pack();
		frame.setVisible(true); 
 
	}
 
} | 
Partager