コード例 #1
0
		/// <summary>
		/// Read the properties of the first bitmap to finish initializing the writer.
		/// </summary>
		/// <param name="bitmap">First bitmap</param>
		private void Initialize(Bitmap mBitmap,string licenseURL,string licenseIssuerURL)
		{
			AMMediaType mtype = new AMMediaType();

			VideoInfoHeader videoInfoHeader = new VideoInfoHeader();

			// Create the VideoInfoHeader using info from the bitmap
			videoInfoHeader.BmiHeader.Size = Marshal.SizeOf(typeof(BitmapInfoHeader));
			videoInfoHeader.BmiHeader.Width = mBitmap.Width;
			videoInfoHeader.BmiHeader.Height = mBitmap.Height;
			videoInfoHeader.BmiHeader.Planes = 1;                

			// compression thru clrimportant don't seem to be used. Init them anyway
			videoInfoHeader.BmiHeader.Compression = 0;
			videoInfoHeader.BmiHeader.ImageSize = 0;
			videoInfoHeader.BmiHeader.XPelsPerMeter = 0;
			videoInfoHeader.BmiHeader.YPelsPerMeter = 0;
			videoInfoHeader.BmiHeader.ClrUsed = 0;
			videoInfoHeader.BmiHeader.ClrImportant = 0;

			switch(hBitmap.PixelFormat)
			{
			case PixelFormat.Format32bppRgb:
				mtype.subType = MediaSubType.RGB32;
				videoInfoHeader.BmiHeader.BitCount = 32;
				break;
			case PixelFormat.Format24bppRgb:
				mtype.subType = MediaSubType.RGB24;
				videoInfo.BmiHeader.BitCount = 24;
				break;
			case PixelFormat.Format16bppRgb555:
				mtype.subType = MediaSubType.RGB555;
				videoInfo.BmiHeader.BitCount = 16;
				break;
			default:
				throw new Exception("Unrecognized Pixelformat in bitmap");
			}

			videoInfoHeader.SrcRect = new Rectangle(0, 0, mBitmap.Width, mBitmap.Height);
			videoInfoHeader.TargetRect = videoInfoHeader.SrcRect;
			videoInfo.BmiHeader.ImageSize = mBitmap.Width * mBitmap.Height * (videoInfoHeader.BmiHeader.BitCount / 8);
			videoInfo.BitRate = videoInfoHeader.BmiHeader.ImageSize * mFrameRate;
			videoInfo.BitErrorRate = 0;
			videoInfo.AvgTimePerFrame = 10000 * 1000 / mFrameRate;

			mtype.majorType = MediaType.Video;
			mtype.fixedSizeSamples = true;
			mtype.temporalCompression = false;
			mtype.sampleSize = mediaHeader.ImageSize;
			mtype.formatType = FormatType.VideoInfo;
			mtype.unkPtr = IntPtr.Zero;
			mtype.formatSize = Marshal.SizeOf(typeof(VideoInfoHeader));

			GCHandle gHandle = GCHandle.Alloc(mediaHeader, GCHandleType.Pinned);

			try
			{
				// Set the inputprops using the structures
				mtype.formatPtr = gHandle.AddrOfPinnedObject();


			}
			finally
			{
				gHan.Free();
				mt.formatPtr = IntPtr.Zero;
			}


			byte[] bytes = (byte[])mtype;
			mediaWriter.Write ( bytes);

		}
コード例 #2
0
        private void ConfigureMediaWriter(int width, int height, Guid mediaSubType, short bitCount)
        {
            AMMediaType mediaType = new AMMediaType();
            VideoInfoHeader videoInfo = new VideoInfoHeader();

            // Create the VideoInfoHeader using info from the bitmap
            videoInfo.BmiHeader.Size = Marshal.SizeOf(typeof(BitmapInfoHeader));
            videoInfo.BmiHeader.Width = width;
            videoInfo.BmiHeader.Height = height;
            videoInfo.BmiHeader.Planes = 1;

            // compression thru clrimportant don't seem to be used. Init them anyway
            videoInfo.BmiHeader.Compression = 0;
            videoInfo.BmiHeader.ImageSize = 0;
            videoInfo.BmiHeader.XPelsPerMeter = 0;
            videoInfo.BmiHeader.YPelsPerMeter = 0;
            videoInfo.BmiHeader.ClrUsed = 0;
            videoInfo.BmiHeader.ClrImportant = 0;

            mediaType.subType = mediaSubType;
            videoInfo.BmiHeader.BitCount = bitCount;

            videoInfo.SrcRect = new Rectangle(0, 0, width, height);
            videoInfo.TargetRect = videoInfo.SrcRect;
            videoInfo.BmiHeader.ImageSize = width * height * (videoInfo.BmiHeader.BitCount / 8);
            videoInfo.BitRate = videoInfo.BmiHeader.ImageSize * Constants.VideoFrameRate;
            videoInfo.BitErrorRate = 0;
            videoInfo.AvgTimePerFrame = 10000 * 1000 / Constants.VideoFrameRate;

            mediaType.majorType = MediaType.Video;
            mediaType.fixedSizeSamples = true;
            mediaType.temporalCompression = false;
            mediaType.sampleSize = videoInfo.BmiHeader.ImageSize;
            mediaType.formatType = FormatType.VideoInfo;
            mediaType.unkPtr = IntPtr.Zero;
            mediaType.formatSize = Marshal.SizeOf(typeof(VideoInfoHeader));

            // Lock the videoInfo structure, and put the pointer
            // into the mediatype structure
            GCHandle handle = GCHandle.Alloc(videoInfo, GCHandleType.Pinned);

            try
            {
                // Set the inputprops using the structures
                mediaType.formatPtr = handle.AddrOfPinnedObject();
                MediaProperties.SetMediaType(mediaType);
            }
            finally
            {
                handle.Free();
                mediaType.formatPtr = IntPtr.Zero;
            }

            // Now take the inputprops, and set them on the file writer
            MediaWriter.SetInputProps(VideoChannelIndex, MediaProperties);
        }