したがって、演習として、ファイルから JFIF (JPEG) データを読み取っています (すでにこれを行っているライブラリがあることは知っていますが、それらを探しているわけではありません)。画像ファイルのサイズ、色深度、寸法は既に取得しています。ただし、実際の画像データを取得する方法がよくわかりません。16 進エディターでデータを調べましたが、それを実際の画像と比較しても、どこにも行きません。誰かがこれを開始するための優れたリソースを持っている場合 (おそらく困難で啓発的なプロセスであることはわかっていますが、それが私がそれを行っている理由です)、それは素晴らしいことです。
コンテキストのためだけに、これまでの私のコード:
// check header data, assign header data to important fields
// Start Of Image (SOI) must be FFD8 and the next marker must be FF
if(!(this.data[0] == (byte) 0xFF && this.data[1] == (byte) 0xD8
&& this.data[2] == (byte) 0xFF))
this.isValid = false;
// check if file is not valid
if(!isValid)
log.log(Level.SEVERE,
String.format("ERROR: File %s is not registered as a JFIF!\n", this.filename),
new IllegalArgumentException());
// If the next values are correct, then the data stream starts at SOI
// If not, the data stream is raw
this.isRawDataStream = !(this.data[3] == (byte) 0xE0
&& this.data[6] == (byte) 0x4A
&& this.data[7] == (byte) 0x46
&& this.data[8] == (byte) 0x49
&& this.data[9] == (byte) 0x46
&& this.data[10] == (byte) 0x00);
// Read until SOF0 marker (0xC0)
int i = 11;
while(this.data[i] != (byte) 0xC0) {
i++;
}
System.out.println("SOF0 marker at offset " + i);
// Skip two bytes, next byte is the color depth
this.colorDepth = this.data[i+3];
// Next two bytes are the image height
String h = String.format("%02X", this.data[i+4]) + String.format("%02X", this.data[i+5]);
this.height = hexStringToInt(h);
System.out.println("Height: " + this.height);
// Next two bytes are the image width
String w = String.format("%02X", this.data[i+6]) + String.format("%02X", this.data[i+7]);
this.width = hexStringToInt(w);
System.out.println("Width: " + this.width);
System.out.println("Color depth: " + this.colorDepth);
// load pixels into an image
this.image = new BufferedImage(this.width,
this.height,
BufferedImage.TYPE_INT_RGB);
次に、各ピクセルを取得して画像に送信する必要があります。各ピクセルとそれぞれの RGB データを取得するにはどうすればよいですか?