473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Create a Bitmap of a webpage programmatically...how?

Hi everyone,
I have a pesky little problem that is driving me nuts.
I'm trying to capture an image of a web page programmatically in a
background thread or process.
What I'd like to do is create a Bitmap object of a webpage from, say,
the new WebBrowser control of .net 2.0 or even the old ActiveX browser
control, without opening any forms.

I tried with the new WebBrowser control, but the only thing I've managed
to do is open up a form with the control in it, and do a screen capture
of a rectangle the same size of the control.
But the problem is that I need to do it /without/ opening the Form. :(
I think I'm getting close, but I really can't find a way to do it as a
background process.

Can anyone please point me in the right direction?

Thanks

--
Joe Black
Nov 17 '05 #1
3 2553
Interop and the PrintWindow API.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Joe Black" <jo*@black.com> wrote in message
news:DZ*******************@twister2.libero.it...
Hi everyone,
I have a pesky little problem that is driving me nuts.
I'm trying to capture an image of a web page programmatically in a
background thread or process.
What I'd like to do is create a Bitmap object of a webpage from, say, the
new WebBrowser control of .net 2.0 or even the old ActiveX browser
control, without opening any forms.

I tried with the new WebBrowser control, but the only thing I've managed
to do is open up a form with the control in it, and do a screen capture of
a rectangle the same size of the control.
But the problem is that I need to do it /without/ opening the Form. :(
I think I'm getting close, but I really can't find a way to do it as a
background process.

Can anyone please point me in the right direction?

Thanks

--
Joe Black

Nov 17 '05 #2
Thanks for your reply,
I tried with PrintWindow API, but all I get is a black bitmap if try to
capture a control that is not visible.

Here is what i do:

[DllImport("user32.dll")]
private static extern bool PrintWindow(IntPtr hwnd, IntPtr hdcBlt, uint
nFlags);

//...

Bitmap bm = new Bitmap(webBrowser1.Width, this.webBrowser1.Height);
Graphics g = Graphics.FromImage(bm);
IntPtr hdc = g.GetHdc();
Form1.PrintWindow(webBrowser1.Handle, hdc, 0);
g.ReleaseHdc(hdc);
g.Flush();
g.Dispose();
this.pictureBox1.Image = bm;

//...

Am I missing something?

--
Joe Black

Bob Powell [MVP] wrote on 12/04/2005 19.38:
Interop and the PrintWindow API.

Nov 17 '05 #3
On Tue, 12 Apr 2005 15:40:19 GMT, Joe Black <jo*@black.com> wrote:
Hi everyone,
I have a pesky little problem that is driving me nuts.
I'm trying to capture an image of a web page programmatically in a
background thread or process.
What I'd like to do is create a Bitmap object of a webpage from, say,
the new WebBrowser control of .net 2.0 or even the old ActiveX browser
control, without opening any forms.

I tried with the new WebBrowser control, but the only thing I've managed
to do is open up a form with the control in it, and do a screen capture
of a rectangle the same size of the control.
But the problem is that I need to do it /without/ opening the Form. :(
I think I'm getting close, but I really can't find a way to do it as a
background process.

Can anyone please point me in the right direction?

Thanks


I have exactly the same requirement coming at me somewhere down the
road - if you find a solution please let us know.

Ive not given this very much thought myself yet but one idea might be
to use something like virtual print driver
http://www.print-driver.com/... I REALLY dont know if a third party
component would be requied for this but just a thought.

Regards
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Spiegel | last post by:
Hi all, I think this is a longshot, but is there a technique for programmatically run a webpage? Let's say one of our vendors has a page that we go to daily to pick up some files. Each time,...
5
by: Steve Amey | last post by:
Hi all I have an ARGB value for a Colour (Eg. -65536. The value was retrieved by using the Color.ToArgb method), is there any way that I can create a System.Drawing.Image or a...
1
by: Mehdi Mousavi | last post by:
Hi, I need to create a 16x16 blank icon programmatically (in C#) but I've got no idea how to do so. Any help would be highly appreciated, Cheers, Mehdi
3
by: Bradford | last post by:
I have an Windows application that displays lots of different colored lines in a Panel by using the Graphics.DrawLine method. The location and length of each line comes from a database query that...
7
by: John Williams | last post by:
Does anyone know a way of creating a PNG file containing several GIF files programmatically (using Visual Basic)? Here's what I do manually in Fireworks. Each Gif is 200 x 200 pixels. 1....
5
by: Lance | last post by:
I need to create a Drawing.Bitmap from an array of integer values. My current technique creates a bitmap that eventually becomes corrupt (i.e., the bitmap's pixels change to a different color...
2
by: Mad Scientist Jr | last post by:
I have a bitmap (32 pixels high, 8192 pixels wide) that contains 255 images, each 32 pixels wide, that I would like to chop up into individual 32x32 bitmap files. Rather than spending hours in...
0
by: news.microsoft.com | last post by:
Hi guys, This text looks long and complicate but it is not, and I really really need some help here. For the last 24hs I'm trying to resolve this issue (last night I dreamed
2
by: Tina | last post by:
I have a System.Drawing.Bitmap myImage; I also have a webcontrols.Image on my web page. I want to put the bitmap into the image but the image can only get it's bitmap from ImageURL which can be a...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.