## Periodic Capture and Timestamp Image Example

Discussions on extending SharpCap using the built in Python scripting functionality
AllanB
Posts: 2
Joined: Thu May 04, 2017 2:19 pm

### Periodic Capture and Timestamp Image Example

Hi,
Just installed SharpCap with a view to looking at the scripting side.
Unfortunately can't get the example script on the web site to work properly as is gives the error
"A graphics object cannot be created from an image that has an indexed pixel format"

I can see that the image created from the capture is an indexed .png but I cannot see any setting to change this and the script having saved the file as an indexed pixel format then can then not carry out the system drawing of the timestamp.

Can anyone get me working on this?
Thanks
Allan

Posts: 1066
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

### Re: Periodic Capture and Timestamp Image Example

Hi Allan,

are you working with a mono camera or in a mono mode? I'm guessing that would be the cause of the indexed pixel format in the saved file.

The code on this StackOverflow answer (translated from C# to IronPython) will convert the formal of a bitmap for you - https://stackoverflow.com/questions/201 ... in-c-sharp.

So you would change the code like this

Code: Select all

bm = System.Drawing.Bitmap("d:\capture.png")
clone = System.Drawing.Bitmap(bm.Width, bm.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
g = System.Drawing.Graphics.FromImage(clone)
g.DrawImage(bm, 0, 0, bm.Width, bm.Height)
f = System.Drawing.Font("Arial", 12)
g.DrawString(System.DateTime.Now.ToString(), f, System.Drawing.Brushes.Red, System.Drawing.Point(0,0))
g.Dispose()
f.Dispose()
clone.Save("d:\\timestamped.png")
clone.Dispose()
bm.Dispose()

Basically you make a bitmap in a non-indexed format, draw the indexed bitmap into it, then draw on the timestamp on top, then save.

cheers,

Robin

AllanB
Posts: 2
Joined: Thu May 04, 2017 2:19 pm

### Re: Periodic Capture and Timestamp Image Example

Hi Robin,
I was working with a colour camera, I thought in colour mode but whatever the original issue, your help has fixed the problem.

Cheers

Allan.

Posts: 1066
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

### Re: Periodic Capture and Timestamp Image Example

Hi Allan,

you may well be in RAW mode then, in which case the conversion to RGB in the script will cause you all sorts of problems later. I'd suggest switching the colour space to RGB, in which case the extra code should now be required.

See http://docs.sharpcap.co.uk/2.9/#Colour% ... 0Explained for more details on colour spaces.

cheers,

Robin

### Who is online

Users browsing this forum: No registered users and 1 guest