public void ConversionTest() { Color32 c = Color32.FromArgb(0x11223344); Color64 c64 = new Color64(c); Assert.AreEqual(c, c64.ToColor32()); }
public void ConversionTest() { Color32 c = Color32.FromArgb(0x11223344); Color48 c48 = new Color48(c); Assert.AreEqual(c.ToOpaque(), c48.ToColor32()); }
public void ConversionTest() { Color32 c = Color32.FromArgb(0x11223344); Color16Gray c16 = new Color16Gray(c); Assert.AreEqual((ushort)(0x2222 * ColorExtensions.RLum + 0x3333 * ColorExtensions.GLum + 0x4444 * ColorExtensions.BLum), c16.Value); }
protected static void GenerateAlphaGradient(IReadWriteBitmapData bitmapData) { var firstRow = bitmapData.FirstRow; float ratio = 255f / (bitmapData.Width / 6f); float limit = bitmapData.Width / 6f; for (int x = 0; x < bitmapData.Width; x++) { // red -> yellow if (x < limit) { firstRow[x] = new Color32(255, (x * ratio).ClipToByte(), 0); } // yellow -> green else if (x < limit * 2) { firstRow[x] = new Color32((255 - (x - limit) * ratio).ClipToByte(), 255, 0); } // green -> cyan else if (x < limit * 3) { firstRow[x] = new Color32(0, 255, ((x - limit * 2) * ratio).ClipToByte()); } // cyan -> blue else if (x < limit * 4) { firstRow[x] = new Color32(0, (255 - (x - limit * 3) * ratio).ClipToByte(), 255); } // blue -> magenta else if (x < limit * 5) { firstRow[x] = new Color32(((x - limit * 4) * ratio).ClipToByte(), 0, 255); } // magenta -> red else { firstRow[x] = new Color32(255, 0, (255 - (x - limit * 5) * ratio).ClipToByte()); } } if (bitmapData.Height < 2) { return; } var row = bitmapData[1]; ratio = 255f / bitmapData.Height; do { byte a = (255 - row.Index * ratio).ClipToByte(); for (int x = 0; x < bitmapData.Width; x++) { row[x] = Color32.FromArgb(a, firstRow[x]); } } while (row.MoveNextRow()); }