Create Icon from Bitmap

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
JeroenG
User
Posts: 16
Joined: Tue Feb 14, 2017 2:18 pm

Create Icon from Bitmap

Post by JeroenG »

Hi,

I've created a custom button.
In the FullDemo I added an image to the resources (MyIcon.png).
Now I want to add that image as the icon of my custom button.

How to this?

Code: Select all

  IUIX_Inst UiInst = (IUIX_Inst)pdfCtl.Inst.GetExtension("UIX");

            if (UiInst.CmdManager == null || UiInst.CmdManager.Cmds == null)
            {
                return;
            }

            var cmd = UiInst.CmdManager.Cmds.AddNew2(cmdId, 0, pdfEditorCommandHandler);

            if (cmd == null)
            {
                return;
            }

            cmd.Title = "Custom button";

            Bitmap MyIcon = Properties.Resources.MyIcon;
            
            //How can I add my icon as the icon of my command?
            cmd.Icon = MyIcon; ???
            cmd.Icon = uiInst.CreateIconFromIStream(MyIcon) ??? 
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Create Icon from Bitmap

Post by Sasha - Tracker Dev Team »

Hello JeroenG,

Take a look here:
https://forum.pdf-xchange.com/ ... 963#p97973

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
JeroenG
User
Posts: 16
Joined: Tue Feb 14, 2017 2:18 pm

Re: Create Icon from Bitmap

Post by JeroenG »

Hi Alex,

I already found that one.
But I don't want to open an image from disk, and create the icon from there.

I want to add an icon from the bitmap which is in memory.

Is that possible?

Jeroen
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Create Icon from Bitmap

Post by Sasha - Tracker Dev Team »

Hello JeroenG,

Well the sample I gave you uses the CreateIconFromIStream method. Basically you can create the IStream for the memory only usage. Take a look at the FullDemo application - there is a sample on how to use the ISream.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
JeroenG
User
Posts: 16
Joined: Tue Feb 14, 2017 2:18 pm

Re: Create Icon from Bitmap

Post by JeroenG »

Hi Alex,

Can't find anything about the PDFXEdit.IStream in the FullDemo application.

It only contains the IStreamWrapper which implements the System.Runtime.InteropServices.ComTypes.IStream interface.
I don't understand how I can use that in the uiInst.CreateIconFromIStream() function.

Jeroen
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Create Icon from Bitmap

Post by Sasha - Tracker Dev Team »

Hello JeroenG,

Well basically you can push the Bitmap into a memory stream and then use the IStreamWrapper to pass it into the method.
Though I've found a better way of doing this with using Bitmap's handle (if it works for you):

Code: Select all

Bitmap i = (Bitmap)Bitmap.FromFile(System.IO.Directory.GetParent(System.Environment.CurrentDirectory).Parent.FullName + "\\Resources\\calculator.png");
bar.Icon = uiInst.CreateIconFromHandle((uint)i.GetHicon());
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
JeroenG
User
Posts: 16
Joined: Tue Feb 14, 2017 2:18 pm

Re: Create Icon from Bitmap

Post by JeroenG »

Hi,

Thx, that worked! :)

Jeroen
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17910
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Create Icon from Bitmap

Post by Tracker Supp-Stefan »

:D
Post Reply