Failing to WritePixelFast to CanvasBuffer

Archives Forums/BlitzPlus Programming/Failing to WritePixelFast to CanvasBuffer

Pineapple(Posted 2008) [#1]
I have now found the problem, but I need to find out how to fix it.

How do you take a string of text that represents a hexadecimal color code ( $FD4A67 ) and convert it into a format readable by WritePixelFast?

Timjo(Posted 2008) [#2]
Here's how I would do it. It's a fairly clumsy way. I'm sure there is someone out there who could provide a slicker solution.

It's basically just stripping out each 'Letter' from the string you provided, finding it's decimal value using it's ascii value, and multiplying up according to it's positon in the string.

ie: right to left dec * 2^0 ..... dec *2^4 .... dec *2^8 etc..
The last operation puts it in the correct format.
The final value 'colour_val' should be useable with writepixelfast.


colour_hex$="$FD4A67" ; your text string



For string_pos=7 To 2 Step-1


If asc_val>=65 And asc_val<=70
colour_val=colour_val+( (asc_val-64+9) * multiply) ; A to F
colour_val=colour_val+( (asc_val-48) * multiply) ; 0 to 9

multiply=multiply Shl 4



There is also a post in these forums about converting colour values which might be of use..Here's the link:

Hope this helps. Tim.

Pineapple(Posted 2008) [#3]
Thank you very much for your help. Now once I polish this thing up it'll probably end up in the showcase!

Would like a mention someplace?

Timjo(Posted 2008) [#4]
You're welcome B+man, glad it was useful. Let me know when you finish the project. The demos looked really clever.

(Yes, I am part of the 8%..but it was so long ago I can't even remember being a teenager - guess that's why I'm in that 8% ).

Pineapple(Posted 2008) [#5]
Well, I don't feel that it's yet ready for the showcase, but here's the latest version.

You can follow QuickSand's progress here.

Download QuickSand v1.1 Alpha 2.5