Created
December 5, 2019 03:24
-
-
Save TakashiYoshinaga/2e2671c512d3ea7d75ea496c14ec35d8 to your computer and use it in GitHub Desktop.
Transformation of ColorImage into Depth Image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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