473,387 Members | 1,771 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,387 software developers and data experts.

Save graphics image to bitmap?

dgk
I'm trying to save the image of a webbrowser control. Not a particular
image being shown on the page, but rather the visible display of the
webbrowser. Using VS2005 I figured that maybe DrawToBitmap would work,
but it appears that the webbrowser doesn't implement it.

So I looked around and found that this code:

Dim g As Graphics
g.CopyFromScreen(Me.wb1.PointToScreen(New Point(0, 0)), New
Point(0, 0), wb1.Size)

should get the image into a graphics object. What I can't figure out
is how to get that into a bitmap that I can hang on to. This:

dim b as Bitmap = g.???

doesn't appear to be the correct approach; at least nothing works.

Is there some way to do this or am I going about it wrong? I can use
SnagIt or even PrintScreen to dump it into the clipboard so there must
be some way to get at it. Any help greatly appreciated.
Apr 8 '06 #1
15 7158
dgk,

A image in a webpage (therefore as well in the webbrowser) has to be forever
an image (or Java, Flash program or whatever related for web) as an url.

Therefore working with bitmaps in a webbrowser is withouth any sense.

You have to set the picture (url) too an absolute place in the browser or
create first something as a table to fix it on its place.

I hope this helps,

Cor

"dgk" <No*****@MailsAnonymous.com> schreef in bericht
news:9e********************************@4ax.com...
I'm trying to save the image of a webbrowser control. Not a particular
image being shown on the page, but rather the visible display of the
webbrowser. Using VS2005 I figured that maybe DrawToBitmap would work,
but it appears that the webbrowser doesn't implement it.

So I looked around and found that this code:

Dim g As Graphics
g.CopyFromScreen(Me.wb1.PointToScreen(New Point(0, 0)), New
Point(0, 0), wb1.Size)

should get the image into a graphics object. What I can't figure out
is how to get that into a bitmap that I can hang on to. This:

dim b as Bitmap = g.???

doesn't appear to be the correct approach; at least nothing works.

Is there some way to do this or am I going about it wrong? I can use
SnagIt or even PrintScreen to dump it into the clipboard so there must
be some way to get at it. Any help greatly appreciated.

Apr 8 '06 #2
Hi,

Dock the webbrowser control in a panel. Use the panels drawtobitmap
method.

Dim bmWb As New Bitmap(Panel1.Width, Panel1.Height)
Panel1.DrawToBitmap(bmWb, Panel1.ClientRectangle)

PictureBox2.Image = bmWb
Ken
-------------------
"dgk" <No*****@MailsAnonymous.com> wrote in message
news:9e********************************@4ax.com...
I'm trying to save the image of a webbrowser control. Not a particular
image being shown on the page, but rather the visible display of the
webbrowser. Using VS2005 I figured that maybe DrawToBitmap would work,
but it appears that the webbrowser doesn't implement it.

So I looked around and found that this code:

Dim g As Graphics
g.CopyFromScreen(Me.wb1.PointToScreen(New Point(0, 0)), New
Point(0, 0), wb1.Size)

should get the image into a graphics object. What I can't figure out
is how to get that into a bitmap that I can hang on to. This:

dim b as Bitmap = g.???

doesn't appear to be the correct approach; at least nothing works.

Is there some way to do this or am I going about it wrong? I can use
SnagIt or even PrintScreen to dump it into the clipboard so there must
be some way to get at it. Any help greatly appreciated.

Apr 8 '06 #3
dgk
On Sat, 8 Apr 2006 06:40:07 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

Dock the webbrowser control in a panel. Use the panels drawtobitmap
method.

Dim bmWb As New Bitmap(Panel1.Width, Panel1.Height)
Panel1.DrawToBitmap(bmWb, Panel1.ClientRectangle)

PictureBox2.Image = bmWb
Ken


That was clever but it doesn't work; all I get is a white screen. I
then tried getting rid of the panel and using the form, but I get the
whole form with a big white space where the webbrowser is. I guess
that's why I was having so much trouble doing it straight; the
webbrowser image is sort of outside the scope of the project.

It appears that this is not going to be trivial. Any other ideas?
Apr 8 '06 #4

"dgk" <No*****@MailsAnonymous.com> wrote in message
news:q4********************************@4ax.com...
That was clever but it doesn't work; all I get is a white screen. I
then tried getting rid of the panel and using the form, but I get the
whole form with a big white space where the webbrowser is. I guess
that's why I was having so much trouble doing it straight; the
webbrowser image is sort of outside the scope of the project.

It appears that this is not going to be trivial. Any other ideas?


You are trying to simulate <CTRL>-<PRINT SCREEN> or <PRINT SCREEN> ??

Apr 8 '06 #5
dgk
On Sat, 08 Apr 2006 16:25:37 GMT, "Homer J Simpson"
<no****@nowhere.com> wrote:

"dgk" <No*****@MailsAnonymous.com> wrote in message
news:q4********************************@4ax.com.. .
That was clever but it doesn't work; all I get is a white screen. I
then tried getting rid of the panel and using the form, but I get the
whole form with a big white space where the webbrowser is. I guess
that's why I was having so much trouble doing it straight; the
webbrowser image is sort of outside the scope of the project.

It appears that this is not going to be trivial. Any other ideas?


You are trying to simulate <CTRL>-<PRINT SCREEN> or <PRINT SCREEN> ??

Basically, except that I only want the browser window. My app has the
user go online to a site, and they should be able to capture images of
what they've done as part of the documentation of the process. These
are sites that I have no control over.

I'm thinking that I might need to figure out Bitblt and I've been
poking around at pinvoke.net
(http://www.pinvoke.net/default.aspx/gdi32.BitBlt) but haven't managed
to make it work yet. It doesn't blow up, it just doesn't work.

I also tried grabbing the webbrowser documenttext and just setting it
when I want to recreate the image but that doesn't include any images
in the page. Then I tried just saving the whole document into an
htmldocument object - I had high hopes for this, but
WebBrowser.Document is readonly.

I know it can be done. Snagit does it, printscreen does it without any
granularity, so I can do it. I just need to figure out how to write a
function that takes a webbrowser as a parameter and returns a bitmap.
That sounds easy. I figured that it would take ten minutes and I've
been working on it on and off for three weeks.
Apr 8 '06 #6

"dgk" <No*****@MailsAnonymous.com> wrote in message
news:7l********************************@4ax.com...
I know it can be done. Snagit does it, printscreen does it without any
granularity, so I can do it. I just need to figure out how to write a
function that takes a webbrowser as a parameter and returns a bitmap.
That sounds easy. I figured that it would take ten minutes and I've
been working on it on and off for three weeks.


Have you looked at something like "Programming Windows with C#" by Charles
Petzold or one of his similar books? Maybe even one for Win95/98 etc? I
suspect you MAY be in that territory.

Apr 8 '06 #7
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
A image in a webpage (therefore as well in the webbrowser) has to be
forever an image (or Java, Flash program or whatever related for web) as
an url.


The OP wants to create a screenshot of the page being shown in the
webbrowser control and save it to a bitmap, IMO.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Apr 8 '06 #8
Hi,

I tested it with the msdn home page and it worked. I did not try
this with a flash site so I do not know how this will work with flash. Are
you sure the document completed loading before you got the bitmap. The
webbrowser has a documentcompleted event you should get the image then.

Ken
----------------

"dgk" wrote:
On Sat, 8 Apr 2006 06:40:07 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

Dock the webbrowser control in a panel. Use the panels drawtobitmap
method.

Dim bmWb As New Bitmap(Panel1.Width, Panel1.Height)
Panel1.DrawToBitmap(bmWb, Panel1.ClientRectangle)

PictureBox2.Image = bmWb
Ken


That was clever but it doesn't work; all I get is a white screen. I
then tried getting rid of the panel and using the form, but I get the
whole form with a big white space where the webbrowser is. I guess
that's why I was having so much trouble doing it straight; the
webbrowser image is sort of outside the scope of the project.

It appears that this is not going to be trivial. Any other ideas?

Apr 9 '06 #9
Hi,

Did you try saving the documentstream?

Ken
------------------

"dgk" wrote:
On Sat, 08 Apr 2006 16:25:37 GMT, "Homer J Simpson"
<no****@nowhere.com> wrote:

"dgk" <No*****@MailsAnonymous.com> wrote in message
news:q4********************************@4ax.com.. .
That was clever but it doesn't work; all I get is a white screen. I
then tried getting rid of the panel and using the form, but I get the
whole form with a big white space where the webbrowser is. I guess
that's why I was having so much trouble doing it straight; the
webbrowser image is sort of outside the scope of the project.

It appears that this is not going to be trivial. Any other ideas?


You are trying to simulate <CTRL>-<PRINT SCREEN> or <PRINT SCREEN> ??

Basically, except that I only want the browser window. My app has the
user go online to a site, and they should be able to capture images of
what they've done as part of the documentation of the process. These
are sites that I have no control over.

I'm thinking that I might need to figure out Bitblt and I've been
poking around at pinvoke.net
(http://www.pinvoke.net/default.aspx/gdi32.BitBlt) but haven't managed
to make it work yet. It doesn't blow up, it just doesn't work.

I also tried grabbing the webbrowser documenttext and just setting it
when I want to recreate the image but that doesn't include any images
in the page. Then I tried just saving the whole document into an
htmldocument object - I had high hopes for this, but
WebBrowser.Document is readonly.

I know it can be done. Snagit does it, printscreen does it without any
granularity, so I can do it. I just need to figure out how to write a
function that takes a webbrowser as a parameter and returns a bitmap.
That sounds easy. I figured that it would take ten minutes and I've
been working on it on and off for three weeks.

Apr 9 '06 #10

"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
Hi,

I tested it with the msdn home page and it worked. I did not
try
this with a flash site so I do not know how this will work with flash.
Are
you sure the document completed loading before you got the bitmap. The
webbrowser has a documentcompleted event you should get the image then.


The only thing I've been able to do with flash is, if it supports printing,
print to PrimoPDF.

Apr 9 '06 #11
dgk
On Sun, 9 Apr 2006 06:25:02 -0700, Ken Tucker [MVP]
<Ke**********@discussions.microsoft.com> wrote:
Hi,

Did you try saving the documentstream?

Ken
------------------

"dgk" wrote:


Not until you mentioned it, but it works the same as DocumentText; no
images are saved.
Apr 9 '06 #12
dgk
On Sat, 08 Apr 2006 21:46:39 GMT, "Homer J Simpson"
<no****@nowhere.com> wrote:

"dgk" <No*****@MailsAnonymous.com> wrote in message
news:7l********************************@4ax.com.. .
I know it can be done. Snagit does it, printscreen does it without any
granularity, so I can do it. I just need to figure out how to write a
function that takes a webbrowser as a parameter and returns a bitmap.
That sounds easy. I figured that it would take ten minutes and I've
been working on it on and off for three weeks.


Have you looked at something like "Programming Windows with C#" by Charles
Petzold or one of his similar books? Maybe even one for Win95/98 etc? I
suspect you MAY be in that territory.

I fear so. I think that I might have to dust off an Appleman book that
I thought was safely locked away.
Apr 9 '06 #13
dgk
On Sun, 9 Apr 2006 06:21:01 -0700, Ken Tucker [MVP]
<Ke**********@discussions.microsoft.com> wrote:
Hi,

I tested it with the msdn home page and it worked. I did not try
this with a flash site so I do not know how this will work with flash. Are
you sure the document completed loading before you got the bitmap. The
webbrowser has a documentcompleted event you should get the image then.

Ken
----------------


Odd, I tried it with Google and it didn't work. I'm pretty sure the
site finished loading - I'm not keying off any WebBrowser event, I'm
doing it when the user presses a button on the form containing the
WebBrowser. I'll give it another chance when I get home.
Apr 10 '06 #14
BK
This is something I found on the web a while back, I use it to print
screen shots from within my VB apps. It takes a window and converts it
to a bitmap image using BitBlt (as you mentioned above). It works
great for me and it seems like you could modify it for your purposes.
Hope this helps.

At the top of the form:

Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal hdcDest
As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal
nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr,
ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As
System.Int32) As Boolean
Private Const SRCCOPY As Integer = &HCC0020

Then, in the method where I want to print (modify this to save easily
enough), I have the following snippet:

' Copy the form's image into a bitmap.
m_PrintBitmap = GetFormImage()

' Make a PrintDocument and print.
m_PrintDocument = New PrintDocument
m_PrintDocument.Print()

And finally, the GetFormImage function (that does the heavy lifting) :

Private Function GetFormImage() As Bitmap
' Get this form's Graphics object.
Dim me_gr As Graphics = Me.CreateGraphics

' Make a Bitmap to hold the image.
Dim bm As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height,
me_gr)
Dim bm_gr As Graphics = me_gr.FromImage(bm)
Dim bm_hdc As IntPtr = bm_gr.GetHdc

' Get the form's hDC. We must do this after
' creating the new Bitmap, which uses me_gr.
Dim me_hdc As IntPtr = me_gr.GetHdc

' BitBlt the form's image onto the Bitmap.
BitBlt(bm_hdc, 0, 0, Me.ClientSize.Width, Me.ClientSize.Height,
_
me_hdc, 0, 0, SRCCOPY)
me_gr.ReleaseHdc(me_hdc)
bm_gr.ReleaseHdc(bm_hdc)

' Return the result.
Return bm
End Function

Bill

Apr 10 '06 #15

"BK" <bk******@hotmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
This is something I found on the web a while back, I use it to print
screen shots from within my VB apps. It takes a window and converts it
to a bitmap image using BitBlt (as you mentioned above). It works
great for me and it seems like you could modify it for your purposes.
Hope this helps.


I note "How to: Copy Pixels for Reducing Flicker in Windows Forms" and
"CopyPixelOperation Enumeration" which relate to BitBlt

Apr 11 '06 #16

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

Similar topics

6
by: charsh | last post by:
Hi, I using the code below to draw a text in a pictureBox1. //Start--------------------------------------------------------------- private void button1_Click(object sender, System.EventArgs e)...
4
by: MAY | last post by:
Hi, I drew some lines on a form and i want convert these lines into a bitmap. How can i do that? MAY
12
by: yaya via DotNetMonster.com | last post by:
Hi, I have a picture box with circles and rectangles, and I wana save all the images into a jpg file, i tried pictureBox1.Image.Save(@"c:\1.jpg"); but I got and error...
7
by: Martin | last post by:
I'm using the code show below (in VB.Net 2003) to create an image. I want to save this image to a .PNG file such that when I subsequently display it as part of a web page, the background of the...
1
by: WB | last post by:
Hi, I have a helper class that has a method to resize images. It takes the virtual path of an image and resize it to a specified dimension like this. public void ResizeImageTest(string...
4
by: Yash | last post by:
Have used DrawLine() method to draw some lines in the picturebox (sort of a barcode) in the picturebox paint event. This diagram has to be saved as an image in bmp or tiff format. But the problem...
1
by: Hardy Wang | last post by:
Hi, I found a piece of code to add drop shadow to a photo like below, after I save the image, it is actually a BMP file even though I specify a JPG file extension (see...
12
by: Lee | last post by:
I have the following code using System; using System.Windows.Forms; using System.Drawing; using System.Collections; namespace FINN {
13
by: Joe | last post by:
does anyone know why this source code throws an error?? Dim myBitmap As System.Drawing.Bitmap Dim myGraphics As Graphics myBitmap = New System.Drawing.Bitmap(fileName:="C:\test.tif")...
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.