1

私の問題は、ポインタを取得した後、ピクセルデータを正しく読み取ることです。

したがって、iPhone画面全体を占め、アルファチャネル(ピクセルあたり24ビット、コンポーネントあたり8ビット、行あたり960バイト)を持たない画像があり、特定のピクセルの色を調べたいと思います。

データへのポインタがあります

UInt8 *data = CFDataGetBytePtr(bitmapData);

しかし、座標を指定してデータに正しくインデックスを付ける方法がわかりませんか?

4

1 に答える 1

2
UInt8 *data = CFDataGetBytePtr(bitmapData);

unsigned long row_stride = image_width * no_of_channels; // 960 bytes in this case
unsigned long x_offset = x * no_of_channels;

/* assuming RGB byte order (as opposed to BGR) */
UInt8 r = *(data + row_stride * y + x_offset );
UInt8 g = *(data + row_stride * y + x_offset + 1);
UInt8 b = *(data + row_stride * y + x_offset + 2);


/* less portable but if you want to access it in as a packed UInt32, you could do */
UInt32 color = *(data + row_stride * y + x) & 0x00FFFF;  /* little endian byte ordering */
于 2009-01-12T21:59:12.763 に答える