示例#1
0
 public void SetPixel(int x, int y, int pixel)
 {
     Bitmap.SetPixel(x, y, ColorHelper.FromIntRgb24(pixel));
 }
示例#2
0
        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));
        }
示例#3
0
 public int GetPixel(int x, int y)
 {
     return(ColorHelper.ToIntRgb24(Bitmap.GetPixel(x, y)));
 }