Esempio n. 1
0
        public static BitmapSource GenerateImage(NetworkUsageDataCollection ncollection, Color sentColor,
                                                 Color receiveColor)
        {
            const int width           = 16;
            const int height          = 16;
            long      receiveMaximums = ncollection.GetMaximumAtAll();

            PixelFormat  pf        = PixelFormats.Rgb24;
            const double dpi       = 96;
            int          rawStride = (width * pf.BitsPerPixel + 7) / 8;
            var          pixelData = new byte[rawStride * height];

            try
            {
                //Note : Initialize Palette

                Filler(height, ref pixelData, rawStride, Colors.Gray);

                for (int i = 0; i < width; i++)
                {
                    SetPixel(0, i, Colors.Black, ref pixelData, rawStride);
                    SetPixel(height - 1, i, Colors.Black, ref pixelData, rawStride);
                }
                for (int i = 0; i < height; i++)
                {
                    SetPixel(i, 0, Colors.Black, ref pixelData, rawStride);
                    SetPixel(i, width - 1, Colors.Black, ref pixelData, rawStride);
                }

                // End : Initialize Palette

                int counter = 1;

                for (int i = 0; i < 14; i++)
                {
                    ColumnFiller(ref pixelData, rawStride, counter, height - 2, ncollection[45 + i].ByteReceived,
                                 receiveMaximums, receiveColor);

                    ColumnFiller(ref pixelData, rawStride, counter, height - 2, ncollection[45 + i].ByteSent,
                                 receiveMaximums, sentColor);

                    counter++;
                }
            }
            catch (Exception)
            {
                Trace.WriteLine(String.Format("Something Went Wrong, Time : {0}",
                                              DateTime.Now.ToString(CultureInfo.InvariantCulture)));
            }

            BitmapSource returnValue = BitmapSource.Create(width, height, dpi, dpi, pf, null, pixelData, rawStride);

            return(returnValue);
        }