473,729 Members | 2,150 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
30 3124
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
Nov 20 '05 #11
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.ImageFo rmat.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.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

"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 #12
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******** ********@tk2msf tngp13.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.ImageFo rmat.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.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

"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 #13
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
Nov 20 '05 #14
* "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>
Nov 20 '05 #15
Cor
This is the first bitmap sample that goes to my ofline HKW brainconnector is
it OK?
Nov 20 '05 #16
* "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>
Nov 20 '05 #17
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******** ******@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 #18
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
Nov 20 '05 #19
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.c om> wrote in message
news:u9******** ******@tk2msftn gp13.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

Nov 20 '05 #20

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

Similar topics

1
7134
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
6319
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
10334
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
3623
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
4247
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
8739
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
864
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
4732
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
8913
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
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
9142
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
8144
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
6722
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
6016
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
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2162
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.