private static KeyBitmap GetGrayImage(byte b) { var raw = new byte[72 * 72 * 3]; for (int i = 0; i < raw.Length; i++) { raw[i] = b; } return(KeyBitmap.FromRawBitmap(raw)); }
private static KeyBitmap GetStripeImage(int pos) { var raw = new byte[72 * 72 * 3]; for (int y = 0; y < 72; y++) { var p = (y * 72 + pos) * 3; raw[p + 0] = 255; raw[p + 1] = 255; raw[p + 2] = 255; } return(KeyBitmap.FromRawBitmap(raw)); }
public static KeyBitmap LoadIconByName(string name, bool active) { var assembly = Assembly.GetExecutingAssembly(); var resourceName = $"StreamDeckSharp.Examples.MemoryGame.icons.{name}"; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) using (Bitmap bitmap = (Bitmap)Image.FromStream(stream)) { var raw = ConvertBitmapToRgb24(bitmap); if (!active) { for (int i = 0; i < raw.Length; i++) { raw[i] /= 2; } } return(KeyBitmap.FromRawBitmap(raw)); } }
static KeyBitmap GetKeyImageFromFull(int xPos, int yPos, byte[] fullImageData) { var keyImgData = new byte[buttonPxSize * buttonPxSize * 3]; var xOffset = xPos * (buttonPxSize + buttonPxDist); var yOffset = yPos * (buttonPxSize + buttonPxDist); for (int y = 0; y < buttonPxSize; y++) { var numberOfPixelsInPrevRows = (y + yOffset) * fullPxWidth + xOffset; for (int x = 0; x < buttonPxSize; x++) { var p = (numberOfPixelsInPrevRows + x) * 3; var kPos = (y * buttonPxSize + x) * 3; keyImgData[kPos + 0] = fullImageData[p + 0]; keyImgData[kPos + 1] = fullImageData[p + 1]; keyImgData[kPos + 2] = fullImageData[p + 2]; } } return(KeyBitmap.FromRawBitmap(keyImgData)); }
static void Main(string[] args) { using (var deck = StreamDeck.OpenDevice()) { var sw = Stopwatch.StartNew(); //Create random noise image var rnd = new Random(); var raw = new byte[72 * 72 * 3]; rnd.NextBytes(raw); var rndImage = KeyBitmap.FromRawBitmap(raw); deck.ClearKeys(); //Run a few million SetKeyBitmaps long cnt = 5_000_000; long i = cnt; while (--i > 0) { deck.SetKeyBitmap(7, rndImage); } var t = sw.Elapsed.TotalSeconds; var setKeyTime = t / cnt; //about 0.5µs on my machine Console.WriteLine((setKeyTime * 1000000.0) + " µs"); //Make sure that the test takes a least 3 seconds on your machine // -> change cnt! Console.WriteLine("Total Test time: " + t + " s"); Console.ReadKey(); } }