示例#1
0
        private static Bitmap generateSceneshotInMemory(MediaDetClass mediaDet, double position, int width, int height)
        {
            Bitmap bmp = null;

            unsafe
            {
                //equal to sizeof(CommonClasses.BITMAPINFOHEADER);
                int bmpinfoheaderSize = 40;

                //get size for buffer
                int bufferSize = (((width * height) * 24) / 8) + bmpinfoheaderSize;
                //equal to mediaDet.GetBitmapBits
                //    (0d, ref bufferSize, ref *buffer, target.Width, target.Height);

                //allocates enough memory to store the frame
                IntPtr frameBuffer =
                    System.Runtime.InteropServices.Marshal.AllocHGlobal(bufferSize);
                byte *frameBuffer2 = (byte *)frameBuffer.ToPointer();

                //gets bitmap, save in frameBuffer2
                mediaDet.GetBitmapBits(position,
                                       ref bufferSize, ref *frameBuffer2, width, height);

                //now in buffer2 we have a BITMAPINFOHEADER structure
                //followed by the DIB bits
                IntPtr newImage = new IntPtr(frameBuffer2 + bmpinfoheaderSize);

                bmp = new Bitmap(width, height, width * 3,
                                 System.Drawing.Imaging.PixelFormat.Format24bppRgb, newImage);

                //1. Version
                //bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
                //2. Version
                //bmp.RotateFlip(RotateFlipType.Rotate90FlipX);
                //bmp.RotateFlip(RotateFlipType.Rotate90FlipY);

                //Test
                bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                System.Runtime.InteropServices.Marshal.FreeHGlobal(frameBuffer);
            }
            return(bmp);
        }