Example #1
0
        internal static Image deSerialiseBitmap(byte[] bytes) 
        {
            GDIBitmap gdiBitmap = new GDIBitmap();
            
            gdiBitmap.bmType = getIntFromByteArray(bytes, 0);
            gdiBitmap.bmWidth = getIntFromByteArray(bytes, 4);
            gdiBitmap.bmHeight = getIntFromByteArray(bytes, 8);
            gdiBitmap.bmWidthBytes = getIntFromByteArray(bytes, 12);
            gdiBitmap.bmPlanes = getShortFromByteArray(bytes, 16);
            gdiBitmap.bmBitsPixel = getShortFromByteArray(bytes, 18);
            gdiBitmap.bmBits = getIntFromByteArray(bytes, 20);

            //
            // from
            // http://stackoverflow.com/questions/742236/how-to-create-a-bmp-file-from-byte-in-c-sharp
            //
            unsafe
            {
                fixed (byte* ptr = bytes)
                {
                    int stride = gdiBitmap.bmWidth * 3;
                    //
                    // the new Bitmap(new Bitmap is to get a new copy of the bitmap)
                    //
                    // first we create a bitmap from the bytes array but this array will be garbage collected in the future
                    // so we make a deep copy and then refresh the unsafe bitmap
                    //
                    Bitmap unsafeBitmap = new Bitmap(gdiBitmap.bmWidth, gdiBitmap.bmHeight, -stride, PixelFormat.Format24bppRgb, new IntPtr(ptr + 24 + stride * (gdiBitmap.bmHeight - 1)));
                    Bitmap safeBitmap = new Bitmap(unsafeBitmap);
                    unsafeBitmap.Dispose();
                    return safeBitmap;
                }
            }
        }
Example #2
0
        protected override void Initialize()
        {            
            // Setup a couple of bitmaps
            // First make a bitmap to capture the current screen image
            RectangleI rect = DesktopView.MainDesktopView.Frame;
            fScreenImage = new GDIBitmap("image1", 0, 0, rect.Width, rect.Height);
            GDIRenderer.BitBlt(fScreenImage.GraphDevice.DeviceContext, 0, 0, rect.Width, rect.Height,
                DesktopView.MainDesktopView.GraphDevice.DeviceContext,
                0, 0, TernaryRasterOps.SRCCOPY);

            // Then make a bitmap we'll draw transitions onto
            fBlankImage = new GDIBitmap("image2", 0, 0, rect.Width, rect.Height);
            fBlankImage.ClearToWhite();

            // Load a picture
            fPicture = new GDIBitmap("LEAP.jpg",0,0);
            fPictureImage = new GDIBitmap("leap", 0, 0, rect.Width, rect.Height);
            int xoff = (rect.Width - fPicture.Width) / 2;
            int yoff = (rect.Height - fPicture.Height) / 2;
            fPictureImage.GraphDevice.DrawImage(fPicture,xoff,yoff,fPicture.Width,fPicture.Height);

            // Load some sound to play
            fPlayer = new SoundPlayer("c:\\media\\sounds\\BlueSkyMine.wma");
            fPlayer.Play();
            Animate();

            this.Quit();
        }
Example #3
0
        internal static Image deSerialiseBitmap(byte[] bytes)
        {
            GDIBitmap gdiBitmap = new GDIBitmap();

            gdiBitmap.bmType       = getIntFromByteArray(bytes, 0);
            gdiBitmap.bmWidth      = getIntFromByteArray(bytes, 4);
            gdiBitmap.bmHeight     = getIntFromByteArray(bytes, 8);
            gdiBitmap.bmWidthBytes = getIntFromByteArray(bytes, 12);
            gdiBitmap.bmPlanes     = getShortFromByteArray(bytes, 16);
            gdiBitmap.bmBitsPixel  = getShortFromByteArray(bytes, 18);
            gdiBitmap.bmBits       = getIntFromByteArray(bytes, 20);

            //
            // from
            // http://stackoverflow.com/questions/742236/how-to-create-a-bmp-file-from-byte-in-c-sharp
            //
            unsafe
            {
                fixed(byte *ptr = bytes)
                {
                    int stride = gdiBitmap.bmWidth * 3;
                    //
                    // the new Bitmap(new Bitmap is to get a new copy of the bitmap)
                    //
                    // first we create a bitmap from the bytes array but this array will be garbage collected in the future
                    // so we make a deep copy and then refresh the unsafe bitmap
                    //
                    Bitmap unsafeBitmap = new Bitmap(gdiBitmap.bmWidth, gdiBitmap.bmHeight, -stride, PixelFormat.Format24bppRgb, new IntPtr(ptr + 24 + stride * (gdiBitmap.bmHeight - 1)));
                    Bitmap safeBitmap   = new Bitmap(unsafeBitmap);

                    unsafeBitmap.Dispose();
                    return(safeBitmap);
                }
            }
        }