2016-10-01 134 views
0

我試圖從使用C#創建的簡單網絡瀏覽器拍攝屏幕截圖。 這裏是我到目前爲止發現從Flash Player屏幕截圖內容

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 Player的緩存並從中導出圖像的方式?

回答