Skip to content

Instantly share code, notes, and snippets.

@TakashiYoshinaga
Created December 5, 2019 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TakashiYoshinaga/2e2671c512d3ea7d75ea496c14ec35d8 to your computer and use it in GitHub Desktop.
Save TakashiYoshinaga/2e2671c512d3ea7d75ea496c14ec35d8 to your computer and use it in GitHub Desktop.
Transformation of ColorImage into Depth Image
private void SetColorBitmap(Capture capture)
{
//カラー画像をDepth画像の位置に合わせる
Image colorImage = transformation.ColorImageToDepthCamera(capture);
//各Pixelの色情報を格納した配列を取得
BGRA[] colorArray = colorImage.GetPixels<BGRA>().ToArray();
//colorBitmapへの書き込み準備
BitmapData bitmapData = colorBitmap.LockBits(new Rectangle(0, 0, colorBitmap.Width, colorBitmap.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
unsafe
{
//各ピクセルの値へのポインタ
byte* pixels = (byte*)bitmapData.Scan0;
int index = 0;
//1ピクセルずつ処理
for (int i = 0; i < colorArray.Length; i++)
{
pixels[index++] = colorArray[i].B;
pixels[index++] = colorArray[i].G;
pixels[index++] = colorArray[i].R;
pixels[index++] = 255;//Alpha値を固定して不透過に
}
}
//書き込み終了
colorBitmap.UnlockBits(bitmapData);
//用済みのcolorImageのメモリを解放
colorImage.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment