Ejemplo n.º 1
0
        public override void Paint(System.Drawing.Graphics g, IPaintContext paintContext)
        {
            if (null == _cachedArea)
            {
                return;
            }

            bool orientationIsVertical = IsOrientationVertical;
            bool scaleIsReversed       = IsScaleReversed;

            int pixelH = orientationIsVertical ? _bitmapPixelsAcross : _bitmapPixelsAlong;
            int pixelV = orientationIsVertical ? _bitmapPixelsAlong : _bitmapPixelsAcross;

            if (null == _bitmap || _bitmap.Width != pixelH || _bitmap.Height != pixelV)
            {
                if (null != _bitmap)
                {
                    _bitmap.Dispose();
                }

                _bitmap = new Bitmap(pixelH, pixelV, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            }

            Data.AltaxoVariant porg;
            Data.AltaxoVariant pend;
            NumericalScale     originalZScale;

            Plot.IColorProvider colorProvider;

            if (null != PlotItem)
            {
                porg           = PlotItem.Style.Scale.OrgAsVariant;
                pend           = PlotItem.Style.Scale.EndAsVariant;
                originalZScale = PlotItem.Style.Scale;
                colorProvider  = PlotItem.Style.ColorProvider;
            }
            else
            {
                porg           = 0;
                pend           = 1;
                originalZScale = new LinearScale();
                colorProvider  = new Plot.ColorProvider.ColorProviderBGRY();
            }

            var legendScale       = (NumericalScale)ScaleWithTicks;
            var legendTickSpacing = ScaleWithTicks.TickSpacing;

            // Fill the bitmap

            for (int i = 0; i < _bitmapPixelsAlong; i++)
            {
                double r     = (scaleIsReversed ^ orientationIsVertical) ? 1 - i / (double)(_bitmapPixelsAlong - 1) : i / (double)(_bitmapPixelsAlong - 1);
                double l     = originalZScale.PhysicalToNormal(legendScale.NormalToPhysical(r));
                var    color = colorProvider.GetColor(l);
                if (orientationIsVertical)
                {
                    for (int j = 0; j < _bitmapPixelsAcross; j++)
                    {
                        _bitmap.SetPixel(j, i, color);
                    }
                }
                else
                {
                    for (int j = 0; j < _bitmapPixelsAcross; j++)
                    {
                        _bitmap.SetPixel(i, j, color);
                    }
                }
            }

            var graphicsState = g.Save();

            TransformGraphics(g);

            {
                // Three tricks are neccessary to get the color legend (which is the bitmap) drawn smooth and uniformly:
                // Everything other than this will result in distorted image, or soft (unsharp) edges
                var graphicsState2 = g.Save();                   // Of course, save the graphics state so we can make our tricks undone afterwards
                g.InterpolationMode = InterpolationMode.Default; // Trick1: Set the interpolation mode, whatever it was before, back to default
                g.PixelOffsetMode   = PixelOffsetMode.Default;   // Trick2: Set the PixelOffsetMode, whatever it was before, back to default

                g.DrawImage(_bitmap,
                            new RectangleF(0, 0, (float)Size.X, (float)Size.Y),
                            new Rectangle(0, 0, pixelH - 1, pixelV - 1), GraphicsUnit.Pixel); // Trick3: Paint both in X and Y direction one pixel less than the source bitmap acually has, this prevents soft edges

                g.Restore(graphicsState2);                                                    // make our tricks undone here
            }
            _axisStyles.Paint(g, paintContext, _cachedArea);

            g.Restore(graphicsState);
        }
Ejemplo n.º 2
0
		public override void Paint(System.Drawing.Graphics g, IPaintContext paintContext)
		{
			if (null == _cachedArea)
				return;

			bool orientationIsVertical = IsOrientationVertical;
			bool scaleIsReversed = IsScaleReversed;

			int pixelH = orientationIsVertical ? _bitmapPixelsAcross : _bitmapPixelsAlong;
			int pixelV = orientationIsVertical ? _bitmapPixelsAlong : _bitmapPixelsAcross;

			if (null == _bitmap || _bitmap.Width != pixelH || _bitmap.Height != pixelV)
			{
				if (null != _bitmap)
					_bitmap.Dispose();

				_bitmap = new Bitmap(pixelH, pixelV, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
			}

			Data.AltaxoVariant porg;
			Data.AltaxoVariant pend;
			NumericalScale originalZScale;
			Plot.IColorProvider colorProvider;

			if (null != PlotItem)
			{
				porg = PlotItem.Style.Scale.OrgAsVariant;
				pend = PlotItem.Style.Scale.EndAsVariant;
				originalZScale = PlotItem.Style.Scale;
				colorProvider = PlotItem.Style.ColorProvider;
			}
			else
			{
				porg = 0;
				pend = 1;
				originalZScale = new LinearScale();
				colorProvider = new Plot.ColorProvider.ColorProviderBGRY();
			}

			var legendScale = (NumericalScale)ScaleWithTicks;
			var legendTickSpacing = ScaleWithTicks.TickSpacing;

			// Fill the bitmap

			for (int i = 0; i < _bitmapPixelsAlong; i++)
			{
				double r = (scaleIsReversed ^ orientationIsVertical) ? 1 - i / (double)(_bitmapPixelsAlong - 1) : i / (double)(_bitmapPixelsAlong - 1);
				double l = originalZScale.PhysicalToNormal(legendScale.NormalToPhysical(r));
				var color = colorProvider.GetColor(l);
				if (orientationIsVertical)
				{
					for (int j = 0; j < _bitmapPixelsAcross; j++)
						_bitmap.SetPixel(j, i, color);
				}
				else
				{
					for (int j = 0; j < _bitmapPixelsAcross; j++)
						_bitmap.SetPixel(i, j, color);
				}
			}

			var graphicsState = g.Save();
			TransformGraphics(g);

			{
				// Three tricks are neccessary to get the color legend (which is the bitmap) drawn smooth and uniformly:
				// Everything other than this will result in distorted image, or soft (unsharp) edges
				var graphicsState2 = g.Save(); // Of course, save the graphics state so we can make our tricks undone afterwards
				g.InterpolationMode = InterpolationMode.Default; // Trick1: Set the interpolation mode, whatever it was before, back to default
				g.PixelOffsetMode = PixelOffsetMode.Default;  // Trick2: Set the PixelOffsetMode, whatever it was before, back to default

				g.DrawImage(_bitmap,
					new RectangleF(0, 0, (float)Size.X, (float)Size.Y),
					new Rectangle(0, 0, pixelH - 1, pixelV - 1), GraphicsUnit.Pixel); // Trick3: Paint both in X and Y direction one pixel less than the source bitmap acually has, this prevents soft edges

				g.Restore(graphicsState2); // make our tricks undone here
			}
			_axisStyles.Paint(g, paintContext, _cachedArea);

			g.Restore(graphicsState);
		}