Example #1
0
        public override PixelBuffer ReadPixels(PixelFormat format, Rectangle rect)
        {
            if (format == PixelFormat.Any)
            {
                format = PixelFormat.RGBA8888;
            }

            rect.X += mSourceRect.X;
            rect.Y += mSourceRect.Y;

            int    pixelStride = 4;
            int    size        = mTextureSize.Width * mTextureSize.Height * pixelStride;
            int    memStride   = pixelStride * mTextureSize.Width;
            IntPtr memory      = Marshal.AllocHGlobal(size);

            GL.BindTexture(TextureTarget.Texture2D, mTextureID);
            GL.GetTexImage(TextureTarget.Texture2D, 0, OTKPixelFormat.Rgba,
                           PixelType.UnsignedByte, memory);

            byte[] data = new byte[rect.Width * rect.Height * pixelStride];

            unsafe
            {
                for (int i = rect.Top; i < rect.Bottom; i++)
                {
                    int    dataIndex = (i - rect.Top) * pixelStride * rect.Width;
                    IntPtr memPtr    = (IntPtr)((byte *)memory + i * memStride + rect.Left * pixelStride);

                    Marshal.Copy(memPtr, data, dataIndex, pixelStride * rect.Width);
                }
            }

            Marshal.FreeHGlobal(memory);

            if (format == PixelFormat.RGBA8888)
            {
                return(new PixelBuffer(format, SurfaceSize, data));
            }
            else
            {
                return(new PixelBuffer(format, SurfaceSize, data, PixelFormat.RGBA8888));
            }
        }
Example #2
0
        public override PixelBuffer ReadPixels(PixelFormat format, Geometry.Rectangle rect)
        {
            BitmapData data = mImage.LockBits(Interop.Convert(rect), ImageLockMode.ReadOnly,
                                              System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            if (format == PixelFormat.Any)
            {
                format = PixelFormat.BGRA8888;
            }

            PixelBuffer buffer = new PixelBuffer(format, rect.Size);

            byte[] bytes = new byte[4 * rect.Width * rect.Height];

            Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);

            mImage.UnlockBits(data);

            buffer.SetData(bytes, PixelFormat.BGRA8888);

            return(buffer);
        }
Example #3
0
 public override PixelBuffer ReadPixels(PixelFormat format)
 {
     return(ReadPixels(format, new Rectangle(Point.Empty, SurfaceSize)));
 }