473,698 Members | 2,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question: Saving form as jpeg or gif automatically

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!
Nov 20 '05 #1
30 3112
This link is from an earlier post

<http://groups.google.de/groups?q=gro...=de&lr=&ie=UTF
-8&selm=cuwHx16C CHA.1908%40cpms ftngxa07&rnum=1 >

"VB Programmer" <gr*********@ go-intech.com> wrote in message
news:O9******** ******@tk2msftn gp13.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!

Nov 20 '05 #2
Hi VBP

The code below will capture the given Control's imagery and return a
BitMap.

You can the use bmp.Save (sFilePath, Imaging.ImageFo rmat.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.CreateGraphic s
Try
gDest = Graphics.FromIm age(bmp)
Try
hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
hdcDest, 0, 0, _
c.Width, c.Height, _
hdcSource, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHd c(hdcDest)
End Try
Finally
gSource.Release Hdc(hdcSource)
End Try
Finally
gDest.Dispose()
End Try
Finally
gSource.Dispose ()
End Try

Return bmp
End Function
</code>
Nov 20 '05 #3
AWESOME! Thanks!
"Fergus Cooney" <fi******@tesco .net> wrote in message
news:Oe******** ******@tk2msftn gp13.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.ImageFo rmat.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.CreateGraphic s
Try
gDest = Graphics.FromIm age(bmp)
Try
hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
hdcDest, 0, 0, _
c.Width, c.Height, _
hdcSource, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHd c(hdcDest)
End Try
Finally
gSource.Release Hdc(hdcSource)
End Try
Finally
gDest.Dispose()
End Try
Finally
gSource.Dispose ()
End Try

Return bmp
End Function
</code>

Nov 20 '05 #4
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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******** ******@tk2msftn gp13.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.ImageFo rmat.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.CreateGraphic s
Try
gDest = Graphics.FromIm age(bmp)
Try
hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
hdcDest, 0, 0, _
c.Width, c.Height, _
hdcSource, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHd c(hdcDest)
End Try
Finally
gSource.Release Hdc(hdcSource)
End Try
Finally
gDest.Dispose()
End Try
Finally
gSource.Dispose ()
End Try

Return bmp
End Function
</code>

Nov 20 '05 #5
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.ImageFo rmat.Bmp)

Regards,
Fergus
Nov 20 '05 #6
Thanks. Awesome responses!

"Fergus Cooney" <fi******@tesco .net> wrote in message
news:eu******** ******@TK2MSFTN GP11.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.ImageFo rmat.Bmp)

Regards,
Fergus

Nov 20 '05 #7
"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>
Nov 20 '05 #8
"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.ImageFo rmat.Bmp)


--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
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>

Nov 20 '05 #10

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

Similar topics

1
7133
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?
5
6318
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 opted to create JPEGs. I have installed JPEG-6b and have checked to see that all of the libraries are in the correct, expected places. But, I am still getting the following error.
6
10329
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 120''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
3
3620
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 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll
4
4246
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 my particular requirements.
7
8732
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 returning a bitmap instance. In my asp.net code I think I should call this method to return a bitmap and then somehow stream it using the response object to the Webcontrols.image. Is that right? The image object is on a page with a number of...
0
859
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 signature from a .jpeg file (I think I know how to do this also). What I would like to do then is to save an image of the whole form in a database table (maybe in an image or text coulmn) and be able to redisplay/print this at a later date. ...
4
1987
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 writes the data from sys.stdin to a file which is stat'ed by another script called asyncornously from javascript. In the end I am able to make a progress bar for file uploads via http. Anyway, I have printed sys.stdin to a file and looked at it...
5
4731
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 date stamped on the lower right part of the picture. (I'm not an advanced programmer so my code may not be 100% efficient - sorry, I'm still learning) Everything works fine until the saving part. I've been able to read the file into a...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9028
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7728
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.