Convert IColor to Drawing.Color

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
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Convert IColor to Drawing.Color

Post by lidds »

Please could you help as I cannot seem to figure this out and have spent a good amount of time searching the forum.

All I want to do is convert an IColor to the equivalent Drawing.Color. e.g.

Code: Select all

Dim annotColor As Color =  Color.FromArgb(annot.Data.Color.RGB)


Thanks

Simon
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8588
Joined: Wed Jan 03, 2018 6:52 pm

Re: Convert IColor to Drawing.Color

Post by TrackerSupp-Daniel »

Hi, lidds

Is this intended to be in the SDK forums? you seem to have posted on the End user Forums instead. Please let me know which SDK this is pertaining to and I can move the topic to the appropriate forum for you.

Kind regards,
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Convert IColor to Drawing.Color

Post by lidds »

Hi Daniel,

Yes my mistake it is meant to be in the PDF Xchange Editor SDK forum. If you could move it that would be great.

Thanks

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

Re: Convert IColor to Drawing.Color

Post by Sasha - Tracker Dev Team »

Hello Simon,

Please check the CoreAPIDemo application for the Annotations samples - there are many places that the color is being set:
https://github.com/tracker-software/PDF ... tations.cs

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Convert IColor to Drawing.Color

Post by lidds »

Alex,

I don't want to set the colour of the annotation, I know how to do this. I want to get the colour of the annotation as Drawing.Color

Thanks

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

Re: Convert IColor to Drawing.Color

Post by Sasha - Tracker Dev Team »

Hello lidds,

We have this method in the FullDemo application:

Code: Select all

public static Color rgb2clr(int c)
{
	int r = c & 0x000000FF;
	int g = (c & 0x0000FF00) >> 8;
	int b = (c & 0x00FF0000) >> 16;
	return Color.FromArgb(r, g, b);
}
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Convert IColor to Drawing.Color

Post by lidds »

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

Convert IColor to Drawing.Color

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Convert IColor to Drawing.Color

Post by lidds »

Hi Alex,

Sorry to bring this forum back up again, however I'm not sure if I am passing the correct value to get converted (I am using the following value annot.Data.Color.RGB which is returning a value example of 4282400768) as I get the following error:
ColorError.png
I'm sure I am doing something stupid, but am unsure as to how to convert the color and what value to use?

Thanks

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

Re: Convert IColor to Drawing.Color

Post by Sasha - Tracker Dev Team »

Hello lidds,

The Color should be in the 0XFFAABBCC format. First one is alpha (that is not used), then all of the other components based on code.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Convert IColor to Drawing.Color

Post by lidds »

Hi Alex,

Thanks for the information however what property do I get that colour value from on the annotation item as there is no property that returns that value, see screen shot:
Color.png
Sorry for asking what might be a simple question

Thanks

Simon
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Convert IColor to Drawing.Color

Post by lidds »

Don't worry Alex I figured it out, thanks for your help.

Code: Select all

Public Function IColorToColor(ByVal IColourRGB As UInteger) As Color
        Dim hexColour As String = Hex(IColourRGB)
        hexColour = hexColour.Substring(hexColour.Length - 6)

        Dim r As String = hexColour.Substring(4, 2)
        Dim g As String = hexColour.Substring(2, 2)
        Dim b As String = hexColour.Substring(0, 2)

        Return ColorTranslator.FromHtml("#" & r & g & b)
    End Function
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Convert IColor to Drawing.Color

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply