Code archives/Graphics/WritePixelFast color
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Call like this: rgba=ColorInt(red%, green%, blue%, alpha%) This function has a long history: The function was originally for data compression, turning integers into a single integer. Also useful for sending integers over the network without worrying about bigendian/littleendian confusion. Yes, the simple way is to send a string. The original function was a lot longer and slower than this. However, I updated it to this: Function CompressInts(n1%,n2%,n3%,n4%) a%=n1+(n2 Shl 8)+(n3 Shl 16)+((n4 Mod 128) Shl 24) If n4>128 Then a=a-2147483648 Return a End Function I found for doing stuff with WritePixelFast, I needed an integer form of a color. This function did that but it did it a little strangly. It had to be sent the colors in this order: blue, green, red, alpha I updated it for this release to the form found in the code below. | |||||
Function ColorInt(r1%,g2%,b3%,a4%) c%=b+(g Shl 8)+(r Shl 16)+((a Mod 128) Shl 24) If a>128 Then c=c-2147483648 Return c End Function |
Comments
None.
Code Archives Forum