Skip to main content
10 events
when toggle format what by license comment
Dec 16, 2016 at 13:40 comment added Comintern @CodyGray - Corrected. (I wasn't really concentrating on the byte order when I banged this out).
Dec 16, 2016 at 13:40 history edited Comintern CC BY-SA 3.0
edited body
Dec 16, 2016 at 10:55 comment added Cody Gray I started to play around with this, and upon closer inspection, your code (specifically, RgbToHex2) is not actually correct. You cannot simply reverse the byte order of the long value. In memory on Windows, RGB colors are represented as AABBGGRR, whereas in the hex format, they are AARRGGBB. So you should only be swapping the order of the red and blue components. Felix's original code is correct, but yours produces a different answer.
Dec 15, 2016 at 1:49 comment added RubberDuck Take this one step further and create a 3 byte RGB Type and you've got a great API to work with that doesn't represent RGB as a long. Just food for thought.
Dec 14, 2016 at 20:16 comment added Comintern @ThunderFrame - Probably. I always forget that VBA doesn't use it.
Dec 14, 2016 at 20:10 comment added ThunderFrame @Comintern Could you perhaps ignore the Alpha byte? Saves you a byte assignment.
Dec 14, 2016 at 20:00 vote accept Felix Dombek
Dec 16, 2016 at 16:02
Dec 14, 2016 at 19:23 comment added Comintern @CodyGray - Probably true I'm testing in VBA (so I can't benchmark the optimizations). I'd be curious to see how bit-shifting with division compares to CopyMemory.
Dec 14, 2016 at 19:13 comment added Cody Gray The slow parts are the calls to Hex and Right. It seems that you could further speed up the code by removing the overhead of the calls to CopyMemory and replacing them with simple bit manipulation. With optimization enabled, these operations should be transformed into very fast code. Math operations are definitely going to be faster than an API call.
Dec 14, 2016 at 17:55 history answered Comintern CC BY-SA 3.0