Ejemplo n.º 1
0
        public TBG(Size size, TBGPixelFormat format)
        {
            this.Size        = size;
            this.PixelFormat = format;
            int pixelSize = TBGPixelFormats.GetSize(format);

            this._data = new byte[size.Width * size.Height * pixelSize];
        }
Ejemplo n.º 2
0
        public static TBG FromBitmap(Bitmap bmp)
        {
            var tbgFormat = TBGPixelFormat.BGRA;
            var bmpFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb;

            if (bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)
            {
                tbgFormat = TBGPixelFormat.BGR;
                bmpFormat = System.Drawing.Imaging.PixelFormat.Format32bppRgb;
            }
            int pixelSize = TBGPixelFormats.GetSize(tbgFormat);

            var data    = new byte[bmp.Width * bmp.Height * pixelSize];
            var bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bmpFormat);

            Marshal.Copy(bmpData.Scan0, data, 0, data.Length);
            bmp.UnlockBits(bmpData);

            return(new TBG(bmp.Size, tbgFormat, data));
        }