Ejemplo n.º 1
0
        private static uint BitmapSize(BITMAPINFOHEADER bih)
        {
            uint bis = (uint)((((uint)bih.Width * (uint)bih.BitCount) + 31) & (~31)) / 8;

            return((uint)((uint)bih.Height * bis));
        }
Ejemplo n.º 2
0
        private void GetOutPutCapability()
        {
            if (this.iamsc == null)
            {
                return;
            }

            int iCount = 0, iSize = 0;
            VIDEO_STREAM_CONFIG_CAPS scc;
            IntPtr       ipscc = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(VIDEO_STREAM_CONFIG_CAPS)));
            _AMMediaType mt, cmt;
            IntPtr       ipmt  = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(_AMMediaType)));
            IntPtr       ipcmt = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(_AMMediaType)));

            try
            {
                // clear output size list first
                this.OutPutSizeList.Clear();
                this.MediaTypeList.Clear();
                this.cbxSize.Items.Clear();

                iamsc.GetFormat(out ipmt);

                cmt = (_AMMediaType)Marshal.PtrToStructure(ipmt, typeof(_AMMediaType));

                iamsc.GetNumberOfCapabilities(out iCount, out iSize);

                if (iSize == Marshal.SizeOf(typeof(VIDEO_STREAM_CONFIG_CAPS)))
                {
                    for (int iFormat = 0; iFormat < iCount; iFormat++)
                    {
                        iamsc.GetStreamCaps(iFormat, out ipmt, ipscc);
                        mt  = (_AMMediaType)Marshal.PtrToStructure(ipmt, typeof(_AMMediaType));
                        scc = (VIDEO_STREAM_CONFIG_CAPS)Marshal.PtrToStructure(ipscc, typeof(VIDEO_STREAM_CONFIG_CAPS));

                        if ((mt.majortype == cmt.majortype) &&
                            (mt.subtype == cmt.subtype) &&
                            (mt.formattype == cmt.formattype) &&
                            (mt.cbFormat >= Marshal.SizeOf(typeof(VIDEOINFOHEADER))) &&
                            (mt.pbFormat != null))
                        {
                            this.OutPutSizeList.Add(scc.MaxOutputSize);

                            VIDEOINFOHEADER vih = (VIDEOINFOHEADER)Marshal.PtrToStructure(mt.pbFormat,
                                                                                          typeof(VIDEOINFOHEADER));
                            BITMAPINFOHEADER bih = vih.BitmapInfo;

                            bih.Width      = scc.MaxOutputSize.Width;
                            bih.Height     = scc.MaxOutputSize.Height;
                            bih.SizeImage  = BitmapSize(vih.BitmapInfo);
                            vih.BitmapInfo = bih;
                            this.MediaTypeList.Add(mt);
                            this.cbxSize.Items.Add(scc.MaxOutputSize.Width.ToString() + "x" + scc.MaxOutputSize.Height.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fail to get output size: " + ex.Message);
            }
            finally
            {
                if (ipcmt != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ipcmt);
                }
                if (ipscc != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ipscc);
                }
                if (ipmt != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ipmt);
                }
            }
        }