Greetings folks,
My apologies in advance if this has been asked before, but I can't find anything relevant.
How does one link a bitmap to a custom button? The example shows:
SharpCap.AddCustomButton("Test", None, "Select the first camera", selectFirstCamera)
The pop-up information shows the second parameter allows you to add an image, but I cant figure out how to get a bitmap (BMP) file linked in. The example I found in the Windows .Net documentation show a C++ example, which doesn't quite seem to map nicely to IronPython.
Of course, I can always just forget about the pretty bitmap (a text-only button works just fine), but this is bugging me. It ought to be easy, but I'm missing something.
AddCustomButton bitmap
- admin
- Site Admin
- Posts: 17342
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: AddCustomButton bitmap
Hi,
what you need is a .NET Bitmap object (https://learn.microsoft.com/en-us/dotne ... sktop-10.0) - strictly speaking the parameter takes the base class of 'Image', but in most cases you will want to pass a bitmap.
Then you can pass the bitmap to the AddCustomButton call. I think the default size you should provide is 16x16 pixels, although larger sizes will be reduced down to a maximum of 16x16. It's usually best to do the reduction yourself as you get to control the settings on how the image is reduced in size and manually tweak anything that doesn't quite look right.
cheers,
Robin
what you need is a .NET Bitmap object (https://learn.microsoft.com/en-us/dotne ... sktop-10.0) - strictly speaking the parameter takes the base class of 'Image', but in most cases you will want to pass a bitmap.
Code: Select all
>>> clr.AddReference("System.Drawing")
>>> from System.Drawing import Bitmap
>>> b = Bitmap("f:\\test.png")
cheers,
Robin
Re: AddCustomButton bitmap
That worked perfectly -- damned if I know how I missed it.
Thanks very much, Robin
Thanks very much, Robin
-
Jean-Francois
- Posts: 822
- Joined: Sun Oct 13, 2019 10:52 am
- Location: Germany
Re: AddCustomButton bitmap
Hello,
good to know that it is possible to load the image directly.
But take care to have not too much details in the image ... they will disappear in the small icon.
I use the other method ... first generate an icon image from the image (with an online converter) and then load it directly in the function SharpCap.AddCustomButton().
Regards,
Jean-Francois
good to know that it is possible to load the image directly.
But take care to have not too much details in the image ... they will disappear in the small icon.
I use the other method ... first generate an icon image from the image (with an online converter) and then load it directly in the function SharpCap.AddCustomButton().
Regards,
Jean-Francois
Re: AddCustomButton bitmap
Yes, crafting icons is a tricky business. Over the years, I designed a lot of them, and eventually got the hang of it. I never found a converter I liked, but perhaps they've gotten better.