示例#1
0
        public Bitmap ExportBitmapFromFrameNumber(int position)
        {
            if (position > countFrames)
            {
                throw new Exception("Problem podczas otwierania pliku AVI" + Environment.NewLine + "Upewnij się, że plik nie został poddany kompresji");
            }

            int pDib = AviReadingMethods.AVIStreamGetFrame(getFrameObject, firstFrame + position);

            AviReadingMethods.BITMAPINFOHEADER bih = new AviReadingMethods.BITMAPINFOHEADER();
            bih = (AviReadingMethods.BITMAPINFOHEADER)Marshal.PtrToStructure(new IntPtr(pDib), bih.GetType());

            if (bih.biSizeImage < 1)
            {
                throw new Exception("Problem podczas otwierania pliku AVI" + Environment.NewLine + "Upewnij się, że plik nie został poddany kompresji");
            }

            byte[] bitmapData = new byte[bih.biSizeImage];
            int address = pDib + Marshal.SizeOf(bih);
            for (int offset = 0; offset < bitmapData.Length; offset++)
            {
                bitmapData[offset] = Marshal.ReadByte(new IntPtr(address));
                address++;
            }

            byte[] bitmapInfo = new byte[Marshal.SizeOf(bih)];
            IntPtr ptr;
            ptr = Marshal.AllocHGlobal(bitmapInfo.Length);
            Marshal.StructureToPtr(bih, ptr, false);
            address = ptr.ToInt32();
            for (int offset = 0; offset < bitmapInfo.Length; offset++)
            {
                bitmapInfo[offset] = Marshal.ReadByte(new IntPtr(address));
                address++;
            }

            AviReadingMethods.BITMAPFILEHEADER bfh = new AviReadingMethods.BITMAPFILEHEADER();
            bfh.bfType = AviReadingMethods.BMP_MAGIC_COOKIE;
            bfh.bfSize = (Int32)(55 + bih.biSizeImage);
            bfh.bfReserved1 = 0;
            bfh.bfReserved2 = 0;
            bfh.bfOffBits = Marshal.SizeOf(bih) + Marshal.SizeOf(bfh);

            BinaryWriter bw = new BinaryWriter(new MemoryStream());

            bw.Write(bfh.bfType);
            bw.Write(bfh.bfSize);
            bw.Write(bfh.bfReserved1);
            bw.Write(bfh.bfReserved2);
            bw.Write(bfh.bfOffBits);
            bw.Write(bitmapInfo);
            bw.Write(bitmapData);

            var bitmapToReturn = new Bitmap(bw.BaseStream);

            bw.Close();

            return bitmapToReturn;
        }
示例#2
0
        private void CreateStream()
        {
            AviReadingMethods.AVISTREAMINFO strhdr = new AviReadingMethods.AVISTREAMINFO();
            strhdr.fccType = fccType;
            strhdr.fccHandler = fccHandler;
            strhdr.dwScale = 1;
            strhdr.dwRate = frameRate;
            strhdr.dwSuggestedBufferSize = (UInt32)(height * stride);
            strhdr.dwQuality = 10000;
            strhdr.rcFrame.bottom = (UInt32)height;
            strhdr.rcFrame.right = (UInt32)width;
            strhdr.szName = new UInt16[64];

            int result = AviReadingMethods.AVIFileCreateStream(aviFile, out aviStream, ref strhdr);
            if (result != 0) { throw new Exception("Problem podczas tworzenia streamu pliku AVI" + result.ToString()); }

            AviReadingMethods.BITMAPINFOHEADER bi = new AviReadingMethods.BITMAPINFOHEADER();
            bi.biSize = (UInt32)Marshal.SizeOf(bi);
            bi.biWidth = (Int32)width;
            bi.biHeight = (Int32)height;
            bi.biPlanes = 1;
            bi.biBitCount = 24;
            bi.biSizeImage = (UInt32)(stride * height);

            result = AviReadingMethods.AVIStreamSetFormat(aviStream, 0, ref bi, Marshal.SizeOf(bi));
            if (result != 0) { throw new Exception("Problem podczas tworzenia streamu pliku AVI" + result.ToString()); }
        }
示例#3
0
        public void Open(string fileName)
        {
            AviReadingMethods.AVIFileInit();

            int result = AviReadingMethods.AVIFileOpen(
                ref aviFile, fileName,
                AviReadingMethods.OF_SHARE_DENY_WRITE, 0);

            if (result != 0)
            {
                throw new Exception("Problem podczas otwierania pliku AVI" + Environment.NewLine + "Upewnij się, że plik nie został poddany kompresji");
            }

            result = AviReadingMethods.AVIFileGetStream(
                aviFile,
                out aviStream,
                AviReadingMethods.StreamtypeVIDEO, 0);

            if (result != 0)
            {
                throw new Exception("Problem podczas otwierania pliku AVI" + Environment.NewLine + "Upewnij się, że plik nie został poddany kompresji");
            }

            firstFrame = AviReadingMethods.AVIStreamStart(aviStream.ToInt32());
            countFrames = AviReadingMethods.AVIStreamLength(aviStream.ToInt32());

            streamInfo = new AviReadingMethods.AVISTREAMINFO();
            result = AviReadingMethods.AVIStreamInfo(aviStream.ToInt32(), ref streamInfo, Marshal.SizeOf(streamInfo));

            if (result != 0)
            {
                throw new Exception("Problem podczas otwierania pliku AVI" + Environment.NewLine + "Upewnij się, że plik nie został poddany kompresji");
            }

            bih = new AviReadingMethods.BITMAPINFOHEADER();
            bih.biBitCount = 24;
            bih.biClrImportant = 0;
            bih.biClrUsed = 0;
            bih.biCompression = 0;
            bih.biHeight = (Int32)streamInfo.rcFrame.bottom;
            bih.biWidth = (Int32)streamInfo.rcFrame.right;
            bih.biPlanes = 1;
            bih.biSize = (UInt32)Marshal.SizeOf(bih);
            bih.biXPelsPerMeter = 0;
            bih.biYPelsPerMeter = 0;

            getFrameObject = AviReadingMethods.AVIStreamGetFrameOpen(aviStream, ref bih);
            if (getFrameObject == 0)
            {
                throw new Exception("Problem podczas otwierania pliku AVI" + Environment.NewLine + "Upewnij się, że plik nie został poddany kompresji");
            }
        }