Convert IColor to Drawing.Color

PDF-XChange Editor SDK for Developers

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

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: 451
Joined: Sat May 16, 2009 1:55 pm

Convert IColor to Drawing.Color

Post by lidds » Wed May 20, 2020 7:11 pm

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: 3438
Joined: Wed Jan 03, 2018 6:52 pm

Re: Convert IColor to Drawing.Color

Post by TrackerSupp-Daniel » Wed May 20, 2020 7:17 pm

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,
Daniel McIntyre
Support Technician
Tracker Software Products (Canada) LTD

Support: <Support@tracker-software.com>
Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623

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

Re: Convert IColor to Drawing.Color

Post by lidds » Wed May 20, 2020 8:19 pm

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

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

Re: Convert IColor to Drawing.Color

Post by Sasha - Tracker Dev Team » Thu May 21, 2020 6:47 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

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

Re: Convert IColor to Drawing.Color

Post by lidds » Thu May 21, 2020 9:04 am

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

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

Re: Convert IColor to Drawing.Color

Post by Sasha - Tracker Dev Team » Thu May 21, 2020 9:13 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

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

Re: Convert IColor to Drawing.Color

Post by lidds » Thu May 21, 2020 11:15 am

Thanks Alex

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

Convert IColor to Drawing.Color

Post by Sasha - Tracker Dev Team » Thu May 21, 2020 12:56 pm

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

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

Re: Convert IColor to Drawing.Color

Post by lidds » Fri May 22, 2020 9:47 am

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

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

Re: Convert IColor to Drawing.Color

Post by Sasha - Tracker Dev Team » Fri May 22, 2020 11:48 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

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

Re: Convert IColor to Drawing.Color

Post by lidds » Fri May 22, 2020 1:09 pm

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: 451
Joined: Sat May 16, 2009 1:55 pm

Re: Convert IColor to Drawing.Color

Post by lidds » Tue May 26, 2020 11:12 am

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

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

Convert IColor to Drawing.Color

Post by Sasha - Tracker Dev Team » Tue May 26, 2020 12:20 pm

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply