Screen grab and save as jpeg image

I have a background image I load into the pic control, then I add some text on top of the background image, and then perform a screen grab, capturing both the background image and the text. I have code that currently only works with bitmaps. Does anyone know of some code where I can perform a screen grab and save it as a jpeg?

Is there another way to capture this new image and save it as a file WITHOUT actually displaying the image on the screen?
Malek103197Asked:
Who is Participating?
 
inthedarkConnect With a Mentor Commented:
So take a closer look at what was posted earlier:

Picture1.AutoRedraw = True
Picture1.Picture = LoadPicture("C:\P1.jpg")
Picture1.CurrentX = 0
Picture1.CurrentY = 0
Picture1.Print "Testing";
SavePicture Picture1.Image, "c:\P2.jpg" ' saves image not picture


Boy graphics can be real confusing......
0
 
inthedarkCommented:
>Is there another way to capture this new image and save
>it as a file WITHOUT actually displaying the
>image on the screen?

picYourPicBox.Visible = False


>Does anyone know of some code where I can perform a >screen grab and save it as a jpeg?


' The following won't work.

Picture1.AutoRedraw = True
Picture1.Picture = LoadPicture("C:\P1.jpg")
Picture1.CurrentX = 0
Picture1.CurrentY = 0
Picture1.Print "Testing";
SavePicture Picture1.Image, "c:\P2.jpg"

This might look as if it works but I don't think that VB can save a JPG file. The resulting file P2.JPG is a Bitmap file.

So be able to load and save different types of image files I purchased 3rd party control for about $75.

Pleanty on this site:

http://www.ummah.org.uk/software/softbase/share9.html

I purchased the $29 ImgSource v2.1 from:
http://www.smalleranimals.com/isource.htm
Which you can use if you are happy calling DLL's.

But I also purchased a VB class (imgx) which includes the above for 50$.  But I now see the price has risen to $160.

http://www.atalasoft.com/ImgX/

Purhaps there is some freeware or a cheaper solution?

0
 
glass_cookieCommented:
Hi!

Here's some files for you over the net:

Download...
http://www.planetsourcecode.com/vb/scripts/ShowZip.asp?lngWId=1&lngCodeId=6414&strZipAccessCode=ODE%5F64147843

Description: This code will save a picture box picture as jpg. I didn't write the code. Steve McMahon at the http//vbaccelerator.com did. It's his copywrite. I modified it so it can be anactivex.exe. It orignally was a class and a bas. The ijl11.dll is also required.


Download...
http://www.planetsourcecode.com/vb/scripts/ShowZip.asp?lngWId=1&lngCodeId=8028&strZipAccessCode=ODE%5F80281551

Description: This Code save's the desktop to a bitmap or a jpg file. It uses a dll written in Delphi by me (I know I should put VB code here, but I think this could be usefull)... I have included the dll's code. It can be usefull to capture the screen of a network computer.

That's it!

glass cookie :)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ArkCommented:
http://vbaccelerator.com
FREE dll and sample for saving bitmaps as jpeg
Cheers
0
 
inthedarkCommented:
When you make your choice, bear in mind that if your application needs to be supported way into the future, you need the souce code to all components you are using.  If you need DLL's and you don't have the source, it may not work on Windows XPx.  So you can future proof your app. either by having the source code or writing your own function to inteface with the choosen tool.  In this way you don't have to change your code much if you swap tools later.

p.s. I forgot the reason why I choose Smaller Animals was that full source was supplied.
0
 
ArkCommented:
Just a comment:
vbaccelerator smaple use ijl11.dll from INTEL corporation. It's ALREADY support WindowsXP and I'm sure it'll support all other versions.
Cheers
0
 
ArkCommented:
BTW, full link to source:
http://vbaccelerator.com/codelib/gfx/vbjpeg.htm

Cheers
0
 
Malek103197Author Commented:
OK, I've tried the one from Steve McMahon. It loads a jpeg and then saves it. The problem is I cannot add text on top of it and save the image (including the text). I guess I still need to perform some sort of screen grab.

Also, the Bmp2Jpeg.dll converts a bmp to a jpeg.

I need to load a jpeg, add text on top of it and then save it as a jpeg. If I can perform a screen grab ans then save it as a jpeg that would suffice.
0
 
glass_cookieCommented:
How about saving the screenshot as a bitmap, then convert it as a jpg file?
0
 
Malek103197Author Commented:
glass_cookie,

This is s/w that is running n a server, and I would do away with the bmp altogether as they take up too much space on the hd. I did find a modified version of the Steve McMahon code. It was developed by oigres@postmaster.co.uk, I think I downloaded from vbaccelerator. It perfroms a screen grab and saves it as a jpg, but does this by the user cropping an area with the mouse - I would like to just grab the contents of the picture box. I'll see if I can modify it.
0
 
inthedarkCommented:
>OK, I've tried the one from Steve McMahon. It loads a >jpeg and then saves it. The problem is I cannot
>add text on top of it and save the image (including the >text). I guess I still need to perform some
>sort of screen grab.

Be aware that the image property of a picture box is where what is on the screen.  The picture property is what was loaded from a picture.  So you need to modify your code so it saves the picture image and not the picture property.

Hope this helps.....
0
 
Malek103197Author Commented:
inthedark - you are correct. This does work. However, when I said text, I actually meant that I place a label at a pixel (x,y) position within the picture box, perform the screen grab and then wish to save as a jpeg. Your coed above does work for palcing text, drawing lines - i guess because it is part of the image. I was getting excited when the code worked for text, but, like I said, I guess when you issue the .Print command it becomes part of the image - I'm not sure.

I have a label control that is placed at an x,y coordinates of the pic and then I tried to issue the SavePicture Picture1.Image, "c:\P2.jpg" command but the label does not get captured.

I have found an alternative, I could use the bmp->jpeg dll converter and once I perform a screen grab (coed that I already have). So, like glass cookie said, I will load a jpeg, perform a screen grab to save as a bmp, then convert the bmp to a jpeg, and then kill the bmp.

Unless of course you can help me capture the label cntrl as part of the pic.Image!!
0
 
Malek103197Author Commented:
inthedark - Sometimes the best solution is the most easy. What you gave as the solution is perfect. I need to change the font and print different symbols, and then save the jpeg, and ideally I want the form minimized. Your suggestions satisfies all requirements.

Cheers
0
 
inthedarkCommented:
Malek,

Just one last point, there is a bug with form.image or picture.image in the if you place label boxes on a form/picture box they should be picte up by Image.  But they don;t work.  If you hit this problem you need to use the CaptureWindow API call.  There are several versions of this on the net.

Here is one example, ther are better.  The better examples return a picture of the captured image that you can then save, but this case you will need some extra code to save it as a jpeg.

http://www.allapi.net/tips/capture.php 

Its worth taking a look at other samples.

With these functions you can pickup the active form, or just the client area within the form. You can also modify the code so that they capture a picture box image as well.  

Best of luck and thanks for the points,  forever inthedark...

0
 
plqCommented:
Looking at the accepted answer, the image saved is actually a bitmap, not a jpeg. If you rename a bmp to jpg in windows it still opens successfully, but the actual file format saved list a bitmap

0
All Courses

From novice to tech pro — start learning today.