You are viewing limited content. For full access, please sign in.

Discussion

Discussion

Trouble with Color

SDK
posted on July 15, 2021

We've been working with annotations, and are having trouble getting traditional RGB colors translated accurately.

 

For example, the values of 255,255,128 are the color traditionally used as a highlighter. (See:  https://www.colorschemer.com/rgb-color-codes/ )

 

When we use:

 

Anno.FillColor = Laserfiche.RepositoryAccess.Common.LfColor.FromRgb(FileOperations.Anno.FillColor)

 

and FileOperations.Anno.FillColor is a string value of "225,225,128", we get this color:

 

 

Argb gives us the same value.  Are we missing something obvious?

0 0
replied on July 15, 2021 Show version history

This issue you are running into is that the LfColor.FromRgb() takes either 3 integer inputs (R,G,B) or it takes a single integer input (hex value of RGB converted to integer).  Your code is providing a String object.  The program is then trying to convert the string to an integer.  Since your string of "225,225,128" can be converted to and integer of 225225128, that is what you are passing.  If your input string had been "225, 225, 128", then the code would have thrown an error since this cannot be converted to an integer.  If you want to pass the color as a single string with 3 integers divided by comma, then you need to split the string into the 3 sperate parts.  Try something like this

                    Dim sRGB() As String = FileOperations.Anno.FillColor.Split(",")
                    Dim iR, iG, iB As Integer
                    If Integer.TryParse(sRGB(0), iR) Then
                        If Integer.TryParse(sRGB(1), iG) Then
                            If Integer.TryParse(sRGB(2), iB) Then
                                Anno.FillColor = Laserfiche.RepositoryAccess.Common.LfColor.FromRgb(iR, iG, iB)
                            End If
                        End If
                    End If

 

Otherwise, you can convert your 3 RGB integers to a single integer by something like this

    Private Function RGBtoInteger(ByVal iR As Integer, ByVal iG As Integer, ByVal iB As Integer) As Integer
        Dim iReturn As Integer
        Try
            Dim hexR As String = Hex(iR)
            Dim hexG As String = Hex(iG)
            Dim hexB As String = Hex(iB)
            iReturn = CInt("&H" & hexR & hexG & hexB)
        Catch ex As Exception

        End Try
        Return iReturn
    End Function

 

1 0
replied on July 15, 2021 Show version history

Good Stuff, thanks Bert -

 

I think the payoff line would be like this:

 

SelectColor = Laserfiche.RepositoryAccess.Common.LfColor.FromRgb(iR, iG, iB)

SelectColor being the function I put this into.

0 0
replied on July 15, 2021

I don't see a LfColor.FromRgb that takes a string value.  Does it work if you hard-code it to call FromRgb(255, 255, 128)?

1 0
replied on July 15, 2021

It works perfectly:

Anno.FillColor = Laserfiche.RepositoryAccess.Common.LfColor.FromRgb(255, 255, 128)

Problem is, I'm reading the whole segment from a database as a unit (and as a string). But I see what I need to do with the formatting. Thanks!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.