Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebBrowser.DrawtoBitmap() generating blank images for few sites consistently

I've been using WebBrowser.DrawtoBitmap() in my asp.net page running in separate STA thread to capture web pages as an image. But I found that I'm getting blank images for few sites consistently. I'm aware that the method is not 'officially' supported but it would be nice if someone can provide me any reason or a work around for these blank images issue.

like image 537
NLV Avatar asked Mar 18 '11 12:03

NLV


2 Answers

DrawToBitmap has limitations and dont always work as expected. Try instead work with native GDI+

Here is example

like image 120
Stecya Avatar answered Nov 08 '22 00:11

Stecya


This problem can be solved by giving focus to the control, so it'll draw properly.

This'd be an option, but the control would have to be visible: WebBrowser.DrawToBitmap() or other methods?

As far as I've heard about the problem is that its fixed when you click the webbrowsercontrol. Therefore doing this programmatic should solve the problem :)

I haven't tested this, but in theory I think its possible to launch a windows form in an asp.net application. Reference to system.windows.forms and to drawing, then use application.run on a separate thread. Note: I'm on my phone so I can't test it, but it might actually work.

like image 2
Aidiakapi Avatar answered Nov 08 '22 00:11

Aidiakapi