public override IImage Draw(BitMatrix bitMatrix) { if (bitMatrix == null) { throw new ArgumentNullException(nameof(bitMatrix)); } int rowCount = bitMatrix.RowCount; int columnCount = bitMatrix.ColumnCount; int imageHeight = CellSize * rowCount + Margin * 2; int imageWidth = CellSize * rowCount + Margin * 2; var bitmap = new Bitmap(imageHeight, imageWidth); using (var graph = Graphics.FromImage(bitmap)) { graph.Clear(ColorHelper.FromIntRgb24(Background)); var foreBrush = new SolidBrush(ColorHelper.FromIntRgb24(Foreground)); for (var r = 0; r < rowCount; r += 1) { for (var c = 0; c < columnCount; c += 1) { if (bitMatrix[r, c]) { var x = Margin + c * CellSize; var y = Margin + r * CellSize; graph.FillRectangle(foreBrush, x, y, CellSize, CellSize); } } } } return(new BitmapFrame(bitmap)); }
public override IImage Draw(BitMatrix bitMatrix, ColorMatrix colorMatrix) { if (bitMatrix == null) { throw new ArgumentNullException(nameof(bitMatrix)); } int rowCount = bitMatrix.RowCount; int columnCount = bitMatrix.ColumnCount; int imageHeight = CellSize * rowCount + Margin * 2; int imageWidth = CellSize * rowCount + Margin * 2; var bitmap = new Bitmap(imageHeight, imageWidth); Console.WriteLine(CellSize); Console.WriteLine(rowCount); Console.WriteLine(imageHeight); using (var graph = Graphics.FromImage(bitmap)) { graph.Clear(ColorHelper.FromIntRgb24(Background)); //var foreBrush = new SolidBrush(ColorHelper.FromIntRgb24(Foreground)); var foreBrush = new SolidBrush(Color.FromArgb(40, 40, 40)); var foreBrushB = new SolidBrush(Color.FromArgb(0, 0, 120)); for (var r = 0; r < rowCount; r += 1) { for (var c = 0; c < columnCount; c += 1) { if (bitMatrix[r, c]) { var x = Margin + c * CellSize; var y = Margin + r * CellSize; for (var cmi = 0; cmi < CellSize; cmi++) { for (var cmj = 0; cmj < CellSize; cmj++) { int re = (colorMatrix[CellSize * r + cmi, CellSize *c + cmj] & 0xFF0000) >> 16; int gr = (colorMatrix[CellSize * r + cmi, CellSize *c + cmj] & 0xFF00) >> 8; int bl = colorMatrix[CellSize * r + cmi, CellSize *c + cmj] & 0xFF; //Darken uniformly double h; double s; double l; RgbToHls(re, gr, bl, out h, out l, out s); l = l / (3 * Math.Log(l + 1.5) / Math.Log(2)); //s = 1 - (1-s)/1.25; HlsToRgb(h, l, s, out re, out gr, out bl); Color myColor = Color.FromArgb(re, gr, bl); var foreBrushCustom = new SolidBrush(myColor); graph.FillRectangle(foreBrushCustom, x + cmj, y + cmi, 1, 1); } } } else { var x = Margin + c * CellSize; var y = Margin + r * CellSize; for (var cmi = 0; cmi < CellSize; cmi++) { for (var cmj = 0; cmj < CellSize; cmj++) { int re = (colorMatrix[CellSize * r + cmi, CellSize *c + cmj] & 0xFF0000) >> 16; int gr = (colorMatrix[CellSize * r + cmi, CellSize *c + cmj] & 0xFF00) >> 8; int bl = colorMatrix[CellSize * r + cmi, CellSize *c + cmj] & 0xFF; //Lighten uniformly double h; double s; double l; RgbToHls(re, gr, bl, out h, out l, out s); //l = 1 - (1-l)/6; l = 1 - (1 - l) / (3 * Math.Log((1 - l) + 1.5) / Math.Log(2)); HlsToRgb(h, l, s, out re, out gr, out bl); var foreBrushCustom = new SolidBrush(Color.FromArgb(re, gr, bl)); graph.FillRectangle(foreBrushCustom, x + cmj, y + cmi, 1, 1); } } } } } } return(new BitmapFrame(bitmap)); }
public override IImage Draw(TripMatrix tripMatrix, ColorMatrix colorMatrix) { if (tripMatrix == null) { throw new ArgumentNullException(nameof(tripMatrix)); } Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); int rowCount = colorMatrix.RowCount; int columnCount = colorMatrix.ColumnCount; int imageHeight = rowCount + Margin * 2; int imageWidth = rowCount + Margin * 2; //var bitmap = new Bitmap(imageHeight, imageWidth); var bmp = Bitmap.FromFile("test.jpeg") as Bitmap; Console.WriteLine(CellSize); Console.WriteLine(rowCount); Console.WriteLine(imageHeight); using (var graph = Graphics.FromImage(bmp)) { graph.Clear(ColorHelper.FromIntRgb24(Background)); //var foreBrush = new SolidBrush(ColorHelper.FromIntRgb24(Foreground)); var foreBrush = new SolidBrush(Color.FromArgb(40, 40, 40)); var foreBrushB = new SolidBrush(Color.FromArgb(0, 0, 120)); var foreBrushCustom = new SolidBrush(Color.FromArgb(0, 0, 120)); for (var r = 0; r < rowCount; r += 1) { for (var c = 0; c < columnCount; c += 1) { if (r >= 500 || c >= 500 || tripMatrix[r, c] == 0) { var x = Margin + c; var y = Margin + r; /* * int re = (colorMatrix[r,c] & 0xFF0000) >> 16; * int gr = (colorMatrix[r,c] & 0xFF00) >> 8; * int bl = colorMatrix[r,c] & 0xFF; * * * foreBrushCustom = new SolidBrush(Color.FromArgb(re,gr,bl)); * graph.FillRectangle(foreBrushCustom, x, y, 1,1);*/ //graph.FillRectangle(foreBrush, x, y, 1,1); } else if (tripMatrix[r, c] > 0) { var x = Margin + c; var y = Margin + r; int re = (colorMatrix[r, c] & 0xFF0000) >> 16; int gr = (colorMatrix[r, c] & 0xFF00) >> 8; int bl = colorMatrix[r, c] & 0xFF; //Darken uniformly double h; double s; double l; RgbToHls(re, gr, bl, out h, out l, out s); l = (l * 1) / (tripMatrix[r, c] * Math.Log(l + 1.5) / Math.Log(2)); //s = 1 - (1-s)/1.25; HlsToRgb(h, l, s, out re, out gr, out bl); foreBrushCustom = new SolidBrush(Color.FromArgb(re, gr, bl)); graph.FillRectangle(foreBrushCustom, x, y, 1, 1); } else { var x = Margin + c; var y = Margin + r; int re = (colorMatrix[r, c] & 0xFF0000) >> 16; int gr = (colorMatrix[r, c] & 0xFF00) >> 8; int bl = colorMatrix[r, c] & 0xFF; //Lighten uniformly double h; double s; double l; RgbToHls(re, gr, bl, out h, out l, out s); //l = 1 - (1-l)/6; l = 1 - (1 - l) * 10 / (-1 * tripMatrix[r, c] * Math.Log((1 - l) + 1.5) / Math.Log(2)); HlsToRgb(h, l, s, out re, out gr, out bl); foreBrushCustom = new SolidBrush(Color.FromArgb(re, gr, bl)); graph.FillRectangle(foreBrushCustom, x, y, 1, 1); } } } stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; // Format and display the TimeSpan value. string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("GraphicsTextDrawerTime " + elapsedTime); } return(new BitmapFrame(bmp)); }
public void SetPixel(int x, int y, int pixel) { Bitmap.SetPixel(x, y, ColorHelper.FromIntRgb24(pixel)); }