roChannelPGM = new RandomAccessFile("socketNew\\schiff.pgm", "r").getChannel();
bufferPGM = roChannelPGM.map(FileChannel.MapMode.READ_ONLY, 0, (int)roChannelPGM.size());
protected void paintComponent( Graphics g ) {
int xStart = 10;
int yStart = 10;
String tmpWidth = "";
String tmpHeight= "";
int greyValue = 0;
for(int i=0; i<bufferPGM.limit(); i++){
output.write((char)bufferPGM.get(i));
}
byte[] pgmCodeByte = output.toByteArray();
int[] pgmCode = unsignedByteArrayToInt(pgmCodeByte);
int n = 0;
int count = 0;
// ignoriere Zeichen bis zum 2. LineFeed
while(count != 2){
if(pgmCode[n] == 10)
count++;
n++;
}
//lese Bildbreite:
do{
tmpWidth += String.valueOf((char)pgmCode[n]);
n++;
}while(pgmCode[n] != 32);
widthPGM = Integer.parseInt(tmpWidth);
//lese Bildhöhe:
n++;
do{
tmpHeight += String.valueOf((char)pgmCode[n]);
n++;
}while(pgmCode[n] != 10);
heightPGM = Integer.parseInt(tmpHeight);
//springe bis zum ersten Pixel:
do{
n++;
}while(pgmCode[n] != 10);
System.err.println(pgmCode[n]);
n++;
for(int y=0; y<heightPGM; y++){
for(int x=0; x<widthPGM; x++){
greyValue=pgmCode[n];
g.setColor( new Color( greyValue, greyValue, greyValue) );
g.drawLine( xStart+x, yStart+y, xStart+x, yStart+y );
n++;
}
}
}