Exemple #1
0
        public void GetBitmapHeader()
        {
            IntPtr p = VfwApi.AVIStreamGetFrame(pgf_, 0);

            if (p == IntPtr.Zero)
            {
                throw new VfwException("先頭のフレーム取得に失敗しました。");
            }
            byte[] header = new byte[40];
            Marshal.Copy(p, header, 0, header.Length);
            MemoryStream ms     = new MemoryStream(header);
            BinaryReader reader = new BinaryReader(ms);

            reader.ReadInt32();
            width_  = reader.ReadInt32();
            height_ = reader.ReadInt32();
            if (height_ < 0)
            {
                is_flip_ = false;
                height_  = -height_;
            }
            reader.ReadInt16();
            bit_count_ = reader.ReadUInt16();
            if (bit_count_ != 24 && bit_count_ != 32)
            {
                throw new VfwException("24ビットと32ビットカラー以外には対応していません。");
            }
            ms.Close();
        }
Exemple #2
0
        public Bitmap GetBitmap(int frame_number)
        {
            IntPtr p = VfwApi.AVIStreamGetFrame(pgf_, frame_start_ + frame_number);

            if (p == IntPtr.Zero)
            {
                throw new VfwException("AVIStreamGetFrame", 0);
            }
            p = new IntPtr(p.ToInt32() + 40);
            int stride = (width_ * bit_count_ / 8 + 3) & ~3;

            byte[] buffer = new byte[stride * height_ + 54];
            Marshal.Copy(p, buffer, 0, buffer.Length);
            GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            Bitmap   bitmap = new Bitmap(width_, height_, stride, BitCountToPixelFormat(bit_count_), handle.AddrOfPinnedObject());

            handle.Free();
            if (is_flip_)
            {
                bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            }
            return(bitmap);
        }