locked
black image RRS feed

  • Question

  • User-336662555 posted
    I used the following code in my webpage trying to capture the current IE window.But I always got black image.How can I solve it? Thanks public void CaptureScreen(string fileName,ImageFormat imageFormat) { int hdcSrc = User32.GetWindowDC(User32.GetForegroundWindow()), hdcDest = GDI32.CreateCompatibleDC(hdcSrc), hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, GDI32.GetDeviceCaps(hdcSrc,8),GDI32.GetDeviceCaps(hdcSrc,10)); GDI32.SelectObject(hdcDest,hBitmap); GDI32.BitBlt(hdcDest,0,0,GDI32.GetDeviceCaps(hdcSrc,8), GDI32.GetDeviceCaps(hdcSrc,10), hdcSrc,0,0,0x00CC0020); SaveImageAs(hBitmap,fileName,imageFormat); Cleanup(hBitmap,hdcSrc,hdcDest); } private void Cleanup(int hBitmap,int hdcSrc,int hdcDest) { User32.ReleaseDC(User32.GetForegroundWindow(),hdcSrc); GDI32.DeleteDC(hdcDest); GDI32.DeleteObject(hBitmap); } private void SaveImageAs(int hBitmap,string fileName,ImageFormat imageFormat) { Bitmap image = new Bitmap(Image.FromHbitmap(new IntPtr(hBitmap)), Image.FromHbitmap(new IntPtr(hBitmap)).Width, Image.FromHbitmap(new IntPtr(hBitmap)).Height); image.Save(fileName,imageFormat); }
    Tuesday, April 6, 2004 11:15 AM

All replies

  • User-986063569 posted
    I have exactly the same problem so I'm very interrested in the answer. This code is working fine into a stand alone application but is not working under IIS, I tryed to change the setting of IIS services to allow them to have access to the desktop it doesn't change any thing
    Friday, April 16, 2004 2:30 PM
  • User-986063569 posted
    I think I have the solution, well my windows xp is french so I will try to translate the name as I can... First you have to go in the machine.config file, then change in the processModel tag the value of the userName attribute to System. Then go into the list of windows services and edit the properties of the IIS administration one. Then check the bow "allow to interact with desktop" Now it's working fine on my computer Hope this can help
    Sunday, April 18, 2004 5:41 AM
  • User1059596723 posted
    Try creating a Graphic instead of a bitmap from the handle.
    Wednesday, February 2, 2005 12:33 PM