public static unsafe IImageByte <RgbImageType> ToMetaqubeImage(this Bitmap @this)
        {
            var answer = new ImageByte <RgbImageType>(@this.Width, @this.Height);

            var step = answer.Step;

            var pixels = new int[@this.ByteCount / sizeof(int)];

            @this.GetPixels(pixels, offset: 0, stride: @this.Width, x: 0, y: 0, width: @this.Width, height: @this.Height);

            using (var pin = answer.Open())
            {
                var ptr = pin.Ptr;

                for (var j = 0; j < @this.Height; j++)
                {
                    var pixelPtr = ptr;

                    for (var i = 0; i < @this.Width; i++)
                    {
                        var argb = pixels[j * @this.Width + i];

                        pixelPtr[0] = (byte)((argb >> 16) & 0xFF);
                        pixelPtr[1] = (byte)((argb >> 8) & 0xFF);
                        pixelPtr[2] = (byte)(argb & 0xFF);

                        pixelPtr += step.X;
                    }

                    ptr += step.Y;
                }
            }

            return(answer);
        }
Beispiel #2
0
        public static unsafe IImageByte <RgbImageType> ToMetaqubeImage(this Bitmap @this)
        {
            var answer = new ImageByte <RgbImageType>(@this.Width, @this.Height);

            var step       = answer.Step;
            var dimensions = answer.Dimensions;

            using (var pin = answer.Open())
            {
                var ptr = pin.Ptr;

                for (var j = 0; j < dimensions.Y; j++)
                {
                    var pixelPtr = ptr;

                    for (var i = 0; i < dimensions.X; i++)
                    {
                        var colour = @this.GetPixel(i, j); // TODO: Implement using Bitmap.LockBits

                        pixelPtr[0] = colour.R;
                        pixelPtr[1] = colour.G;
                        pixelPtr[2] = colour.B;

                        pixelPtr += step.X;
                    }

                    ptr += step.Y;
                }
            }

            return(answer);
        }