Cornipsus Posted June 1, 2007 Author Share Posted June 1, 2007 I'm working on a grayscale algorithm, and I need to know how to convert an integer to a byte value. How can I do this? Quote The God of Judgement is not pleased... Link to comment Share on other sites More sharing options...
Cornipsus Posted June 1, 2007 Share Posted June 1, 2007 I'm working on a grayscale algorithm, and I need to know how to convert an integer to a byte value. How can I do this? Quote The God of Judgement is not pleased... Link to comment Share on other sites More sharing options...
BoltBait Posted June 1, 2007 Share Posted June 1, 2007 A simple type cast might do it: ByteVar = (byte)IntVar; Or, if you want to clamp to a byte value: ByteVar = Utility.ClampToByte(IntVar); Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
BoltBait Posted June 1, 2007 Share Posted June 1, 2007 A simple type cast might do it: ByteVar = (byte)IntVar; Or, if you want to clamp to a byte value: ByteVar = Utility.ClampToByte(IntVar); Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
Cornipsus Posted June 1, 2007 Author Share Posted June 1, 2007 Thanks. Quote The God of Judgement is not pleased... Link to comment Share on other sites More sharing options...
Cornipsus Posted June 1, 2007 Author Share Posted June 1, 2007 Thanks. Quote The God of Judgement is not pleased... Link to comment Share on other sites More sharing options...
joejoe Posted June 13, 2007 Share Posted June 13, 2007 I'm working on a grayscale algorithm, and I need to know how to convert an integer to a byte value. How can I do this? If you working with colors then proper way is using ColorBgra class. (properties .R, .G, .B, .A) ColorBgra srcColor = srcArgs.Surface[x, y]; Byte grayByte = (byte)((double)srcColor.R * 0.299 + (double)srcColor.G * 0.587 + (double)srcColor.B * 0.114); ColorBgra destColor; destColor.R = destColor.G = destColor.B = grayByte; destColor.A = 255; In generally you can use divide, modulo and cast operations. uint intVal = 0xAABBCCDD; byte byteR = (byte)((intVal / (256 * 256 * 256)) % 256); // AA byte byteG = (byte)((intVal / (256 * 256 )) % 256); // BB byte byteB = (byte)((intVal / (256 )) % 256); // CC byte byteA = (byte)((intVal ) % 256); // DD Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.