WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: mueer01 on December 19, 2023, 11:58:35 PM

Title: How to make a screenshot?
Post by: mueer01 on December 19, 2023, 11:58:35 PM
Hi all,

I used the example from the function snapshot(). It works, but generates a bitmap only.
Is there any way to generate a screenshot as .jpg or .png ?

Regards,
Erhard
Title: Re: How to make a screenshot?
Post by: td on December 20, 2023, 08:10:42 AM
You would need to perform the conversion yourself. There are several ways to accomplish the task and examples of a few of those methods can be found in the Tech Database. Unfortunately, some of the conversion techniques involve the deprecated Pixie extender or the deprecated ImageMagic COM automation interfaces. There are still several other approaches available for use with WinBatch including Gnuplot and Jim's Omnibus extender which may have some image conversion capacity. I have not used either one so I have no opinion on which option is the best.  You can still download the Pixie extender (WWIMG34I.DLL) but it is not supported and has not been tested for about 10 years.

Other WinBatch users may have better suggestions and if so, will hopefully post on this topic thread.
Title: Re: How to make a screenshot?
Post by: JTaylor on December 20, 2023, 08:36:50 AM
Yes.  My Omnibus Extender will do the conversion.   May be other, better, solutions but can't say.    I still use the Pixie extender in some things, I think, and it still seems to work okay so that might be a solution as well.  Would, obviously, have to test for what you are doing.

         http://www.jtdata.com/anonymous/wbOmnibus.zip

Jim
Title: Re: How to make a screenshot?
Post by: td on December 20, 2023, 01:16:36 PM
The Pixie extender link: https://files.winbatch.com/downloads/wb/WWIMG34I.zip (https://files.winbatch.com/downloads/wb/WWIMG34I.zip)
Title: Re: How to make a screenshot?
Post by: nrr on December 22, 2023, 08:15:43 AM
I use SnagIt from Techsmith.  It is reasonably priced and can capture screen shots and much more, including making a video of everything happening on the screen ... great for creating a training video.  They do provide a free trial.
Nick
Title: Re: How to make a screenshot?
Post by: td on December 22, 2023, 08:39:45 AM
Here is a simple WinBatch solution using WIL CLR hosting(.Net) to convert from .bmp to .jpg format.

Code (winbatch) Select
ObjectClrOption("useany", "System.Drawing")

SysDrawImg = ObjectClrNew("System.Drawing.Image")
Image = SysDrawImg.FromFile("C:\Temp\116_1611.bmp") ; <Your bmp here>
JpegGuid = ObjectClrNew("System.Guid", "b96b3cae-0728-11d3-9d7b-0000f81ef32e") ; Do not ask
ImageFormat = ObjectClrNew("System.Drawing.Imaging.ImageFormat", JpegGuid )
Image.Save("C:\Temp\Example.jpg", ImageFormat.Jpeg)  ; <Your jpeg here>
Image.Finalize() ; Free resources.
Title: Re: How to make a screenshot?
Post by: td on December 22, 2023, 10:20:15 AM
A slightly more convoluted example that creates a jpeg file without an intermediate bmp file.

Code (winbatch) Select
; Formate a screen snapshot shot.
SnapShot(3)
size=BinaryClipGet(0,8)
hBmp=BinaryAlloc(size)
BinaryClipGet(hBmp,8)
hBmp2=BinaryAlloc(size + 14)
BinaryPokeStr(hBmp2, 0, "BM")
BinaryPoke4(hBmp2,2,size + 14)
BinaryPoke4(hBmp2,6,0)
headersize=BinaryPeek4(hBmp,0)
dataoffset = headersize + 14
BinaryPoke4(hBmp2,10,dataoffset)
BinaryCopy(hBmp2,14,hBmp,0,size)

aBmp = ObjectType("array|i1", hBmp2)

ObjectClrOption("useany", "System.IO")
MemStream = ObjectClrNew("System.IO.MemoryStream", aBmp)
BinaryFree(hBmp)
BinaryFree(hBmp2)

ObjectClrOption("useany", "System.Drawing")

SysDrawImg = ObjectClrNew("System.Drawing.Image")
Image = SysDrawImg.FromStream(MemStream) ; Bmp stream
JpegGuid = ObjectClrNew("System.Guid", "b96b3cae-0728-11d3-9d7b-0000f81ef32e") ; Do not ask
ImageFormat = ObjectClrNew("System.Drawing.Imaging.ImageFormat", JpegGuid )
Image.Save("C:\Temp\Example.jpg", ImageFormat.Jpeg)  ; <Your jpeg here>
Image.Finalize() ; Free resources.
exit