Пример #1
0
        public unsafe Image ToDirectCanvasImage(DirectCanvasFactory factory, out ushort minValue, out ushort maxValue)
        {
            Image sourceImage = factory.CreateImage(_width, _height);
            var imageData = sourceImage.Lock(DirectCanvas.Imaging.ImageLock.ReadWrite);
            int numPixels = _width * _height;

            //Image is BGRA format, 4 bytes per pixel
            byte* imagePtr = (byte*)imageData.Scan0.ToPointer();

            minValue = ushort.MaxValue;
            maxValue = ushort.MinValue;

            fixed (ushort* sourceDataPtr = this.DepthPixels)
            {
                ushort* sourcePtr = sourceDataPtr;
                ushort* targetPtr = (ushort*)imagePtr;
                //for (int i = 0; i < numPixels; i++)
                for (int x = 0; x < _width; x++)
                {
                    for (int y = 0; y < _height; y++)
                    {
                        //int i = x + y * _width;
                        //ushort value = sourceData[i];
                        ushort value = *sourcePtr;

                        if (value > maxValue)
                            maxValue = value;
                        if (value > 100 && value < minValue)
                            minValue = value;

                        //pack ushort into first two bytes of pixel
                        //((ushort*)imagePtr)[i * 2] = value;
                        *targetPtr = value;
                        //imagePtr[i * 4] = (byte)(value & 255); //low byte in B
                        //imagePtr[i * 4 + 1] = (byte)(value >> 8); //high byte in G

                        //store 255 in Alpha channel of pixel
                        //imagePtr[i * 4 + 3] = 255;
                        //if (_crop.Contains(x, y))
                        //{
                        //    *(imagePtr + 3) = 255;
                        //}
                        //else
                        //{
                        //    *(imagePtr + 3) = 128;
                        //}

                        sourcePtr++;
                        imagePtr += 4;
                        targetPtr += 1;
                    }
                }
            }

            sourceImage.Unlock(imageData);

            return sourceImage;
        }
Пример #2
0
        public unsafe Image ToDirectCanvasImage(DirectCanvasFactory factory)
        {
            //ushort min, max;
            //return ToDirectCanvasImage(factory, out min, out max);
            Image sourceImage = factory.CreateImage(_width, _height);
            var imageData = sourceImage.Lock(DirectCanvas.Imaging.ImageLock.ReadWrite);
            int numPixels = _width * _height;

            //Image is BGRA format, 4 bytes per pixel
            //byte* imagePtr = (byte*)imageData.Scan0.ToPointer();

            int len = _width * _height * sizeof(ushort);

            //imagePtr[i * 4 + 0] = (byte)(value & 255);  //low byte of pixel 1 in B
            //imagePtr[i * 4 + 1] = (byte)(value >> 8);   //high byte of pixel 1 in G
            //imagePtr[i * 4 + 2] = (byte)(value2 & 255); //low byte of pixel 2 in R
            //imagePtr[i * 4 + 3] = (byte)(value2 >> 8);  //high byte of pixel 2 in A

            fixed (ushort* sourceDataPtr = this.DepthPixels)
            {
                NativeInterop.MoveMemory(imageData.Scan0, (IntPtr)sourceDataPtr, len);
            }
            sourceImage.Unlock(imageData);

            return sourceImage;
        }