屏幕截图从Flash播放器内容

本文关键字:播放器 Flash 屏幕截图 | 更新日期: 2023-09-27 18:09:52

我正在尝试从我使用c#创建的简单web浏览器中截取屏幕截图。这是我到目前为止发现的

public class NativeMethods
{
    [ComImport]
    [Guid("0000010D-0000-0000-C000-000000000046")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    interface IViewObject
    {
        void Draw([MarshalAs(UnmanagedType.U4)] uint dwAspect, int lindex, IntPtr pvAspect, [In] IntPtr ptd, IntPtr hdcTargetDev, IntPtr hdcDraw, [MarshalAs(UnmanagedType.Struct)] ref RECT lprcBounds, [In] IntPtr lprcWBounds, IntPtr pfnContinue, [MarshalAs(UnmanagedType.U4)] uint dwContinue);
    }
    [StructLayout(LayoutKind.Sequential, Pack = 4)]
    struct RECT
    {
        public int Left;
        public int Top;
        public int Right;
        public int Bottom;
    }
    public static void GetImage(object obj, Image destination, Color backgroundColor)
    {
        using (Graphics graphics = Graphics.FromImage(destination))
        {
            IntPtr deviceContextHandle = IntPtr.Zero;
            RECT rectangle = new RECT();
            rectangle.Right = destination.Width;
            rectangle.Bottom = destination.Height;
            graphics.Clear(backgroundColor);
            try
            {
                deviceContextHandle = graphics.GetHdc();
                IViewObject viewObject = obj as IViewObject;
                viewObject.Draw(1, -1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, deviceContextHandle, ref rectangle, IntPtr.Zero, IntPtr.Zero, 0);
            }
            finally
            {
                if (deviceContextHandle != IntPtr.Zero)
                {
                    graphics.ReleaseHdc(deviceContextHandle);
                }
            }
        }
    }
}

如果它是一个普通的网页,这是完美的工作,但是当flash播放器加载内容时,我得到的是空白的黑色图像。我想做的是能够采取屏幕截图从flash内容,即使浏览器是最小化编程当然。

那么有没有办法修改这段代码呢?或者一种访问flash播放器的缓存并从中导出图像的方法?

屏幕截图从Flash播放器内容

找到了另一种方法来拍摄屏幕截图,它足够强大,可以在显示flash内容时工作。

c#中任意控件的屏幕截图