Briefly, how do you save the current form to a jpeg or gif?
Details: I have a form with a speedometer control on it. It continually
loops through a table in a db that has different current "speeds". I want
to "set" the speedometer to the current speed, then save the form as a
picture, then go to the next one, etc... The end result would be a gif or
jpeg that has a "snapshot" of the gauge. (This would eventually show up on
a aspx webform in an image control.)
Any ideas?
Thanks! 30 3073
This link is from an earlier post
< http://groups.google.de/groups?q=gro...=de&lr=&ie=UTF
-8&selm=cuwHx16CCHA.1908%40cpmsftngxa07&rnum=1>
"VB Programmer" <gr*********@go-intech.com> wrote in message
news:O9**************@tk2msftngp13.phx.gbl... Briefly, how do you save the current form to a jpeg or gif?
Details: I have a form with a speedometer control on it. It continually loops through a table in a db that has different current "speeds". I want to "set" the speedometer to the current speed, then save the form as a picture, then go to the next one, etc... The end result would be a gif or jpeg that has a "snapshot" of the gauge. (This would eventually show up
on a aspx webform in an image control.)
Any ideas?
Thanks!
Hi VBP
The code below will capture the given Control's imagery and return a
BitMap.
You can the use bmp.Save (sFilePath, Imaging.ImageFormat.Whatever)
Credit to Armin for this one - I think I got it from one of his posts
elsewhere.
Regards,
Fergus
<code>
Public Declare Function BitBlt Lib "gdi32" ( _
ByVal hDestDC As IntPtr, _
ByVal x As Integer, _
ByVal y As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hSrcDC As IntPtr, _
ByVal xSrc As Integer, _
ByVal ySrc As Integer, _
ByVal dwRop As Integer _
) As Integer
'================================================= ==================
Public Function CaptureControl(ByVal c As Control) As Bitmap
Dim bmp As Bitmap
Dim gDest, gSource As Graphics
Dim hdcSource, hdcDest As IntPtr
bmp = New Bitmap(c.Width, c.Height)
gSource = c.CreateGraphics
Try
gDest = Graphics.FromImage(bmp)
Try
hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
hdcDest, 0, 0, _
c.Width, c.Height, _
hdcSource, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHdc(hdcDest)
End Try
Finally
gSource.ReleaseHdc(hdcSource)
End Try
Finally
gDest.Dispose()
End Try
Finally
gSource.Dispose()
End Try
Return bmp
End Function
</code>
AWESOME! Thanks!
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl... Hi VBP
The code below will capture the given Control's imagery and return a BitMap.
You can the use bmp.Save (sFilePath, Imaging.ImageFormat.Whatever)
Credit to Armin for this one - I think I got it from one of his posts elsewhere.
Regards, Fergus
<code> Public Declare Function BitBlt Lib "gdi32" ( _ ByVal hDestDC As IntPtr, _ ByVal x As Integer, _ ByVal y As Integer, _ ByVal nWidth As Integer, _ ByVal nHeight As Integer, _ ByVal hSrcDC As IntPtr, _ ByVal xSrc As Integer, _ ByVal ySrc As Integer, _ ByVal dwRop As Integer _ ) As Integer
'================================================= ================== Public Function CaptureControl(ByVal c As Control) As Bitmap
Dim bmp As Bitmap Dim gDest, gSource As Graphics Dim hdcSource, hdcDest As IntPtr
bmp = New Bitmap(c.Width, c.Height)
gSource = c.CreateGraphics Try gDest = Graphics.FromImage(bmp) Try hdcSource = gSource.GetHdc Try hdcDest = gDest.GetHdc Try BitBlt( _ hdcDest, 0, 0, _ c.Width, c.Height, _ hdcSource, 0, 0, SRCCOPY _ ) Finally gDest.ReleaseHdc(hdcDest) End Try Finally gSource.ReleaseHdc(hdcSource) End Try Finally gDest.Dispose() End Try Finally gSource.Dispose() End Try
Return bmp End Function </code>
3 quick questions...
I put a button on my winform and tried to call your CaptureControl function
but it kept giving me a "Invalid parameter used" error (unhandled exception
in system.drawing.dll) for the Dim line. Here's the code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As New Bitmap("zzz.bmp")
x = CaptureControl(Me)
End Sub
1. Any ideas? Am I invoking this correctly?
2. Also, it says I have to declare SRCCOPY. Do I just declare it as an
integer?
3. What is BitBlt? I don't see any code? Where is the code?
Thanks.
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl... Hi VBP
The code below will capture the given Control's imagery and return a BitMap.
You can the use bmp.Save (sFilePath, Imaging.ImageFormat.Whatever)
Credit to Armin for this one - I think I got it from one of his posts elsewhere.
Regards, Fergus
<code> Public Declare Function BitBlt Lib "gdi32" ( _ ByVal hDestDC As IntPtr, _ ByVal x As Integer, _ ByVal y As Integer, _ ByVal nWidth As Integer, _ ByVal nHeight As Integer, _ ByVal hSrcDC As IntPtr, _ ByVal xSrc As Integer, _ ByVal ySrc As Integer, _ ByVal dwRop As Integer _ ) As Integer
'================================================= ================== Public Function CaptureControl(ByVal c As Control) As Bitmap
Dim bmp As Bitmap Dim gDest, gSource As Graphics Dim hdcSource, hdcDest As IntPtr
bmp = New Bitmap(c.Width, c.Height)
gSource = c.CreateGraphics Try gDest = Graphics.FromImage(bmp) Try hdcSource = gSource.GetHdc Try hdcDest = gDest.GetHdc Try BitBlt( _ hdcDest, 0, 0, _ c.Width, c.Height, _ hdcSource, 0, 0, SRCCOPY _ ) Finally gDest.ReleaseHdc(hdcDest) End Try Finally gSource.ReleaseHdc(hdcSource) End Try Finally gDest.Dispose() End Try Finally gSource.Dispose() End Try
Return bmp End Function </code>
Hi VBP,
Sorry, I forgot to copy SRCCOPY across.
Const SRCCOPY As Integer = &HCC0020
BitBlt is part of the WinApi, specifically the GDI dll.
This is shown by the declaration:
Public Declare Function BitBlt Lib "gdi32" ( ...) As Integer
The Declare part tells the compiler that there's going to be mention of a
function BitBlt but that the code isn't going to be given at this time. The
Lib "gdi32" part tells it to find the actual routine externally.
Try this.
Dim x As New Bitmap 'Just to say that you want a BitMap
x = CaptureControl(Me)
x.Save ("zzz.bmp", Imaging.ImageFormat.Bmp)
Regards,
Fergus
Thanks. Awesome responses!
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:eu**************@TK2MSFTNGP11.phx.gbl... Hi VBP,
Sorry, I forgot to copy SRCCOPY across. Const SRCCOPY As Integer = &HCC0020
BitBlt is part of the WinApi, specifically the GDI dll. This is shown by the declaration: Public Declare Function BitBlt Lib "gdi32" ( ...) As Integer The Declare part tells the compiler that there's going to be mention
of a function BitBlt but that the code isn't going to be given at this time.
The Lib "gdi32" part tells it to find the actual routine externally.
Try this. Dim x As New Bitmap 'Just to say that you want a BitMap x = CaptureControl(Me) x.Save ("zzz.bmp", Imaging.ImageFormat.Bmp)
Regards, Fergus
"VB Programmer" <gr*********@go-intech.com> scripsit: Details: I have a form with a speedometer control on it. It continually loops through a table in a db that has different current "speeds". I want to "set" the speedometer to the current speed, then save the form as a picture, then go to the next one, etc... The end result would be a gif or jpeg that has a "snapshot" of the gauge. (This would eventually show up on a aspx webform in an image control.)
<http://www.mvps.org/dotnet/dotnet/samples/windowsandforms/downloads/Screenshot.zip>
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
"Fergus Cooney" <fi******@tesco.net> scripsit: function BitBlt but that the code isn't going to be given at this time. The Lib "gdi32" part tells it to find the actual routine externally.
Try this. Dim x As New Bitmap 'Just to say that you want a BitMap
I still don't understand why you declare 'x' as 'New Bitmap'.
x = CaptureControl(Me) x.Save ("zzz.bmp", Imaging.ImageFormat.Bmp)
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Thank you. I appreciate your help.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bm************@ID-208219.news.uni-berlin.de... "VB Programmer" <gr*********@go-intech.com> scripsit: Details: I have a form with a speedometer control on it. It
continually loops through a table in a db that has different current "speeds". I
want to "set" the speedometer to the current speed, then save the form as a picture, then go to the next one, etc... The end result would be a gif
or jpeg that has a "snapshot" of the gauge. (This would eventually show up
on a aspx webform in an image control.)
<http://www.mvps.org/dotnet/dotnet/sa...nloads/Screens
hot.zip> -- Herfried K. Wagner MVP · VB Classic, VB.NET <http://www.mvps.org/dotnet>
Hi Herfried,
Got to keep that garbage collector on its toes!! ;-)
VBP had this.
Dim x As New Bitmap("zzz.bmp")
I took off the (..) but forgot to remove the New too.
Regards,
Fergus
Something weird is happening. It captures whatever is directly BEHIND the
control, rather than the control itself. For example, if I launch it using
Windows Explorer a jpg will be create but it will be of a portion of
Explorer (directly behind the control, and the same size)!
Any ideas?
Here's how I call the capture code (just test code)...
Dim MyBitmap As Bitmap
MyBitmap = CaptureControl(grpGauge)
MyBitmap.Save("c:\zzzz.jpeg", Imaging.ImageFormat.Jpeg)
Here is the CaptureControl code...
Public Declare Function BitBlt Lib "gdi32" ( _
ByVal hDestDC As IntPtr, _
ByVal x As Integer, _
ByVal y As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hSrcDC As IntPtr, _
ByVal xSrc As Integer, _
ByVal ySrc As Integer, _
ByVal dwRop As Integer _
) As Integer
Public Function CaptureControl(ByVal c As Control) As Bitmap
Dim bmp As Bitmap
Dim gDest, gSource As Graphics
Dim hdcSource, hdcDest As IntPtr
Const SRCCOPY As Integer = &HCC0020
bmp = New Bitmap(c.Width, c.Height)
gSource = c.CreateGraphics
Try
gDest = Graphics.FromImage(bmp)
Try
hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
hdcDest, 0, 0, _
c.Width, c.Height, _
hdcSource, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHdc(hdcDest)
End Try
Finally
gSource.ReleaseHdc(hdcSource)
End Try
Finally
gDest.Dispose()
End Try
Finally
gSource.Dispose()
End Try
Return bmp
End Function
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:eu**************@TK2MSFTNGP11.phx.gbl... Hi VBP,
Sorry, I forgot to copy SRCCOPY across. Const SRCCOPY As Integer = &HCC0020
BitBlt is part of the WinApi, specifically the GDI dll. This is shown by the declaration: Public Declare Function BitBlt Lib "gdi32" ( ...) As Integer The Declare part tells the compiler that there's going to be mention
of a function BitBlt but that the code isn't going to be given at this time.
The Lib "gdi32" part tells it to find the actual routine externally.
Try this. Dim x As New Bitmap 'Just to say that you want a BitMap x = CaptureControl(Me) x.Save ("zzz.bmp", Imaging.ImageFormat.Bmp)
Regards, Fergus
NM I think the problem is that the first set of code was in Form_load rather
than being called from a button. When I did this it worked. Don't
understand it yet, but, oh well... it works!
"VB Programmer" <gr*********@go-intech.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... Something weird is happening. It captures whatever is directly BEHIND the control, rather than the control itself. For example, if I launch it
using Windows Explorer a jpg will be create but it will be of a portion of Explorer (directly behind the control, and the same size)!
Any ideas?
Here's how I call the capture code (just test code)... Dim MyBitmap As Bitmap MyBitmap = CaptureControl(grpGauge) MyBitmap.Save("c:\zzzz.jpeg", Imaging.ImageFormat.Jpeg)
Here is the CaptureControl code... Public Declare Function BitBlt Lib "gdi32" ( _ ByVal hDestDC As IntPtr, _ ByVal x As Integer, _ ByVal y As Integer, _ ByVal nWidth As Integer, _ ByVal nHeight As Integer, _ ByVal hSrcDC As IntPtr, _ ByVal xSrc As Integer, _ ByVal ySrc As Integer, _ ByVal dwRop As Integer _ ) As Integer
Public Function CaptureControl(ByVal c As Control) As Bitmap Dim bmp As Bitmap Dim gDest, gSource As Graphics Dim hdcSource, hdcDest As IntPtr Const SRCCOPY As Integer = &HCC0020 bmp = New Bitmap(c.Width, c.Height)
gSource = c.CreateGraphics Try gDest = Graphics.FromImage(bmp) Try hdcSource = gSource.GetHdc Try hdcDest = gDest.GetHdc Try BitBlt( _ hdcDest, 0, 0, _ c.Width, c.Height, _ hdcSource, 0, 0, SRCCOPY _ ) Finally gDest.ReleaseHdc(hdcDest) End Try Finally gSource.ReleaseHdc(hdcSource) End Try Finally gDest.Dispose() End Try Finally gSource.Dispose() End Try Return bmp End Function
"Fergus Cooney" <fi******@tesco.net> wrote in message news:eu**************@TK2MSFTNGP11.phx.gbl... Hi VBP,
Sorry, I forgot to copy SRCCOPY across. Const SRCCOPY As Integer = &HCC0020
BitBlt is part of the WinApi, specifically the GDI dll. This is shown by the declaration: Public Declare Function BitBlt Lib "gdi32" ( ...) As Integer The Declare part tells the compiler that there's going to be mention of a function BitBlt but that the code isn't going to be given at this time. The Lib "gdi32" part tells it to find the actual routine externally.
Try this. Dim x As New Bitmap 'Just to say that you want a BitMap x = CaptureControl(Me) x.Save ("zzz.bmp", Imaging.ImageFormat.Bmp)
Regards, Fergus
Hi VBP,
There will only be background visible during Form_Load because the Form
hasn't been shown yet. This happens when Form_Load returns. You can, however,
call Me.Show explicitly within Form_Load - and then do your capture. You might
have to add a Me.Refresh too, I haven't tested it.
Regards,
Fergus
* "VB Programmer" <gr*********@go-intech.com> scripsit: NM I think the problem is that the first set of code was in Form_load rather than being called from a button. When I did this it worked. Don't understand it yet, but, oh well... it works!
You can only capture visible parts of the window. If the window isn't
visible ('Form_Load'), it won't be captured.
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
This is the first bitmap sample that goes to my ofline HKW brainconnector is
it OK?
* "Cor" <no*@non.com> scripsit: This is the first bitmap sample that goes to my ofline HKW brainconnector is it OK?
;-)
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Quick question....
This seems to work well if the form has the focus. But, if I switch to
another application the images that are captured are in the correct
"location", but the picture is of whatever application has the focus. Any
ideas on how to FORCE the capture on the correct form?
Thanks!
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:eu**************@TK2MSFTNGP11.phx.gbl... Hi VBP,
Sorry, I forgot to copy SRCCOPY across. Const SRCCOPY As Integer = &HCC0020
BitBlt is part of the WinApi, specifically the GDI dll. This is shown by the declaration: Public Declare Function BitBlt Lib "gdi32" ( ...) As Integer The Declare part tells the compiler that there's going to be mention
of a function BitBlt but that the code isn't going to be given at this time.
The Lib "gdi32" part tells it to find the actual routine externally.
Try this. Dim x As New Bitmap 'Just to say that you want a BitMap x = CaptureControl(Me) x.Save ("zzz.bmp", Imaging.ImageFormat.Bmp)
Regards, Fergus
Hi VBP,
Do you mean that the 'focus' application (or some other window) is lying
across the capture area and thus getting picked up?
I believe that this capture works by going to the screen bitmap, so it
doesn't actually care about who's who and what's what. I think it's just a
dumb 'Gimme a Rect, I'll give you some bits' type of operator.
I imagine that you'll have to get that target window out from under before
doing the capture.
Let me know if I'm wrong though, this is the kind of thing where that
would be useful. ;-)
Regards,
Fergus
You are exactly right Fergus.
This application is going to continuously run on a PC. Which means I would
preferably like it to run in the background so I can do other things. Any
ideas how I can get around it? I tried to "Active" the form before I
captured it, but this doesn't work too well.
Thanks!!!!
"Fergus Cooney" <fi*****@post.com> wrote in message
news:u9**************@tk2msftngp13.phx.gbl... Hi VBP,
Do you mean that the 'focus' application (or some other window) is
lying across the capture area and thus getting picked up?
I believe that this capture works by going to the screen bitmap, so it doesn't actually care about who's who and what's what. I think it's just a dumb 'Gimme a Rect, I'll give you some bits' type of operator.
I imagine that you'll have to get that target window out from under
before doing the capture.
Let me know if I'm wrong though, this is the kind of thing where that would be useful. ;-)
Regards, Fergus
* "VB Programmer" <gr*********@go-intech.com> scripsit: This application is going to continuously run on a PC. Which means I would preferably like it to run in the background so I can do other things. Any ideas how I can get around it? I tried to "Active" the form before I captured it, but this doesn't work too well.
You can capture the visible parts of the form only.
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Is there another sub/function that you know of to capture a control to a jpg
image? I really need the controls to be captured regardless of what
application has the current "focus".
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bn************@ID-208219.news.uni-berlin.de... * "VB Programmer" <gr*********@go-intech.com> scripsit: This application is going to continuously run on a PC. Which means I
would preferably like it to run in the background so I can do other things.
Any ideas how I can get around it? I tried to "Active" the form before I captured it, but this doesn't work too well.
You can capture the visible parts of the form only.
-- Herfried K. Wagner MVP · VB Classic, VB.NET <http://www.mvps.org/dotnet>
* "VB Programmer" <gr*********@go-intech.com> scripsit: Is there another sub/function that you know of to capture a control to a jpg image? I really need the controls to be captured regardless of what application has the current "focus".
<http://www.google.com/groups?selm=sQVN4qGXDHA.2000%40cpmsftngxa06.phx.gb l>
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Hi VBP,
Here's a way-out solution, and no idea whether it would work. Extend your
desktop in size so that it is bigger than the screen. Then run the app in the
portion that is currently not shown. The trouble is Windows may well optimise
away all the drawing.
What problems did you have with Activate? Was it trying to do the capture
before the Form got to the top and was redrawn? (Answer: add a delay) Or was
it that it was very disruptive? (Answer: Hmmm. Add a bell to warn you and a
delay?). Or something else?
Regards,
Fergus
Hi Herfried, VBP,
I tried that one when the topic first came up but I had problems with it -
'The object is currently in use elsewhere' was the complaint. This was on a
Control that did stuff in OnPaint. It works fine on a plain old Button. On a
Panel it gave nothing.
VBP,
If you give it a go, you can replace that entire loop with this. It gets
the OnPaint method directly. There's no need to get them all and weed out the
required one.
Dim OnPaintMethod As MethodInfo
OnPaintMethod = ctl.GetType.GetMethod ("OnPaint", _
BindingFlags.Instance Or BindingFlags.NonPublic)
Regards,
Fergus
I'm sorry Fergus, but you just lost me. :(
How can your example help me? (Sorry.)
"Fergus Cooney" <fi*****@post.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl... Hi Herfried, VBP,
I tried that one when the topic first came up but I had problems with
it - 'The object is currently in use elsewhere' was the complaint. This was on
a Control that did stuff in OnPaint. It works fine on a plain old Button. On
a Panel it gave nothing.
VBP, If you give it a go, you can replace that entire loop with this. It
gets the OnPaint method directly. There's no need to get them all and weed out
the required one.
Dim OnPaintMethod As MethodInfo OnPaintMethod = ctl.GetType.GetMethod ("OnPaint", _ BindingFlags.Instance Or BindingFlags.NonPublic)
Regards, Fergus
Your resolution idea is worth a try.
BTW in my timer method I call my "activate" right before I call the
CaptureControl method. It's like this...
Dim MyBitmap As Bitmap
Dim MyForm As frmMain
MyFrmMain.Activate()
MyBitmap = CaptureControl(MyFrmMain.panKnob)
What happens is...
1. I launch the app and it appears.
2. I click on the window behind it.
3. I can see the app in the task bar blinking away. The images captured
are at the correct location, but they capture the active window.
Fergus, you have proved to be a great resource! Thanks a lot!!!
"Fergus Cooney" <fi*****@post.com> wrote in message
news:O2*************@TK2MSFTNGP11.phx.gbl... Hi VBP,
Here's a way-out solution, and no idea whether it would work. Extend
your desktop in size so that it is bigger than the screen. Then run the app in
the portion that is currently not shown. The trouble is Windows may well
optimise away all the drawing.
What problems did you have with Activate? Was it trying to do the
capture before the Form got to the top and was redrawn? (Answer: add a delay) Or
was it that it was very disruptive? (Answer: Hmmm. Add a bell to warn you and
a delay?). Or something else?
Regards, Fergus
I tried this in my Main sub...
Public Sub New(ByVal dblInterval As Double)
MyBase.New(dblInterval)
MyFrmMain.SetDesktopLocation(-200, -200)
MyFrmMain.Show()
End Sub
I tried to force it off the screen, but all the jpgs were black.
I tried to show the form with ShowDialog too, to make it modal, but the
timer code wouldn't run.
Hmmm????
"VB Programmer" <gr*********@go-intech.com> wrote in message
news:eC**************@tk2msftngp13.phx.gbl... Your resolution idea is worth a try.
BTW in my timer method I call my "activate" right before I call the CaptureControl method. It's like this... Dim MyBitmap As Bitmap Dim MyForm As frmMain
MyFrmMain.Activate() MyBitmap = CaptureControl(MyFrmMain.panKnob)
What happens is... 1. I launch the app and it appears. 2. I click on the window behind it. 3. I can see the app in the task bar blinking away. The images captured are at the correct location, but they capture the active window.
Fergus, you have proved to be a great resource! Thanks a lot!!!
"Fergus Cooney" <fi*****@post.com> wrote in message news:O2*************@TK2MSFTNGP11.phx.gbl... Hi VBP,
Here's a way-out solution, and no idea whether it would work. Extend your desktop in size so that it is bigger than the screen. Then run the app
in the portion that is currently not shown. The trouble is Windows may well optimise away all the drawing.
What problems did you have with Activate? Was it trying to do the capture before the Form got to the top and was redrawn? (Answer: add a delay) Or was it that it was very disruptive? (Answer: Hmmm. Add a bell to warn you
and a delay?). Or something else?
Regards, Fergus
Hi VBP,
I was assuming that you'd followed the link that Herfried had given and
got the code for the alternate method.
It 'manually' triggers the OnPaint event for the target Control but passes
in the Graphics context of <your> Bitmap rather than that of the Control. So
the Control is fooled into drawing itself directly onto the Bitmap. There's a
block of code which uses Reflection to find the OnPaint method. My snippet was
just a replacement for that as it does more than is needed.
As I mentioned in my previous post, it works and doesn't work, depending.
It's definitely worth trying out. To save you the hassle, here it is.
Regards,
Fergus
<code>
Public Function PaintControlToBitmap (oControl As Control) As Bitmap
Dim OnPaintMethod As MethodInfo
OnPaintMethod = oControl.GetType.GetMethod ("OnPaint", _
BindingFlags.Instance Or BindingFlags.NonPublic)
If Not OnPaintMethod Is Nothing Then
Dim bmpControl As New Bitmap (oControl.Width, oControl.Height)
Dim gr As Graphics = Graphics.FromImage (bmpControl)
Dim PaintEventArgs As New PaintEventArgs (gr, _
New Rectangle(0, 0, oControl.Width, oControl.Height))
OnPaintMethod.Invoke (oControl, New Object() {PaintEventArgs})
gr.Dispose
Return bmpControl
End If
End Function
</code>
Thanks once again.
I ran the code and all that was saved was a black rectangle, even though it
was the correct size.
Hmmmm....
"Fergus Cooney" <fi*****@post.com> wrote in message
news:u3*************@TK2MSFTNGP10.phx.gbl... Hi VBP,
I was assuming that you'd followed the link that Herfried had given
and got the code for the alternate method.
It 'manually' triggers the OnPaint event for the target Control but
passes in the Graphics context of <your> Bitmap rather than that of the Control.
So the Control is fooled into drawing itself directly onto the Bitmap.
There's a block of code which uses Reflection to find the OnPaint method. My snippet
was just a replacement for that as it does more than is needed.
As I mentioned in my previous post, it works and doesn't work,
depending. It's definitely worth trying out. To save you the hassle, here it is.
Regards, Fergus
<code> Public Function PaintControlToBitmap (oControl As Control) As Bitmap Dim OnPaintMethod As MethodInfo OnPaintMethod = oControl.GetType.GetMethod ("OnPaint", _ BindingFlags.Instance Or BindingFlags.NonPublic)
If Not OnPaintMethod Is Nothing Then Dim bmpControl As New Bitmap (oControl.Width, oControl.Height) Dim gr As Graphics = Graphics.FromImage (bmpControl) Dim PaintEventArgs As New PaintEventArgs (gr, _ New Rectangle(0, 0, oControl.Width, oControl.Height)) OnPaintMethod.Invoke (oControl, New Object() {PaintEventArgs}) gr.Dispose Return bmpControl End If End Function </code>
Hi VBP,
Thet's wut ah wuz afeard of. Ah gut me a nahce cullerful Butt'n bert
nuthin in mah Panel.
Is there any chance that you could put a small project together that I
could play with?
If you can, and you use VS2002, that should fine. If VS2003, could you add
any graphics as independant jpgs because I can't read v2003 resx files.
(Either way, though, - no bin or obj directories, please)
Regards,
Fergus This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michael Johnston |
last post by:
I am saving a BufferedImage as a JPEG file under Windows XP.
I am using the JAI JPEGImageEncoder class.
The JPEG is saved as CMYK but I need RGB.
I cannot figure out how to get RGB. Any help?
|
by: news.west.cox.net |
last post by:
I have a fairly simple Python program that uses Image and ImageDraw to
create poll results on the fly.
Because PIL only supports 256 colors for GIF and BMPs are huge (in
comparison)... I have...
|
by: Christopher Brandsdal |
last post by:
Hi!
I get an error when I run my code
Is there any other way to get te information from my form?
Heres the error I get and the code beneath.
Line 120 is market with ''''''''''''Line...
|
by: cdj |
last post by:
Hi all,
I've got a picturebox on a form, and a save button. When I go to save,
the app craps out with the following error:
==================
An unhandled exception of type...
|
by: CodeRazor |
last post by:
I'm unfamiliar with image manipulation using c#.
How can i resize a jpg that currently exists in a file and save it resized
as a new file.
The examples i've found have been a bit misleading for...
|
by: Marc Pelletier |
last post by:
Hello all,
I have a class which includes a method to create a chart. I want to be able
to call this method from asp.net code as well as windows application code,
so I have sketched it out as...
|
by: jcriv |
last post by:
Hi,
I want to display a web form with a bunch of data displayed in a specific
format(already know how to do this). I want the client to enter a signature
code and I'll display his/her recorded...
|
by: ACB |
last post by:
I am rewriting an existing PERL script I wrote several months ago. It is a
script that is used as the action for a form containing several type="file"
inputs. The script is run unbuffered and...
|
by: TheGanjaMan |
last post by:
Hi everyone,
I'm trying to write up a simple image stamper application that stamps the
Exif date information from the jpegs that I've taken from my digital
camera and saves the new file with the...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
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...
| |