/// <summary>
		/// Copies the current graph as an bitmap image to the clipboard in native bmp format.
		/// </summary>
		/// <param name="doc">Graph to copy to the clipboard.</param>
		/// <param name="dpiResolution">Resolution of the bitmap in dpi. Determines the pixel size of the bitmap.</param>
		/// <param name="backbrush">Brush used to fill the background of the image. Can be <c>null</c>.</param>
		/// <param name="pixelformat">Specify the pixelformat here.</param>
		public static void CopyToClipboardAsBitmap(this GraphDocument doc, int dpiResolution, BrushX backbrush, PixelFormat pixelformat)
		{
			var dao = Current.Gui.GetNewClipboardDataObject();
			System.Drawing.Bitmap bitmap = GraphDocumentExportActions.RenderAsBitmap(doc, backbrush, pixelformat, dpiResolution, dpiResolution);
			dao.SetImage(bitmap);
			Current.Gui.SetClipboardDataObject(dao);
		}
		public static Bitmap RenderAsBitmap(this GraphDocument document, EmbeddedObjectRenderingOptions renderingOptions, PixelFormat pixelFormat = PixelFormat.Format32bppArgb)
		{
			BrushX opaqueGround = null;
			if (!GraphExportOptions.HasPixelFormatAlphaChannel(pixelFormat))
				opaqueGround = new BrushX(renderingOptions.BackgroundColorForFormatsWithoutAlphaChannel);

			return RenderAsBitmap(document, opaqueGround, renderingOptions.BackgroundBrush, pixelFormat, renderingOptions.SourceDpiResolution, renderingOptions.SourceDpiResolution * renderingOptions.OutputScalingFactor);
		}
    public bool InitializeDocument(params object[] args)
    {
      if (args == null || args.Length == 0)
        return false;

      if (args[0] != null && !(args[0] is BrushX))
        return false;

      _doc =  (BrushX)args[0];

      return true;
    }
		/// <summary>
		/// Saves the graph as an bitmap file and returns the bitmap.
		/// </summary>
		/// <param name="doc">The graph document to export.</param>
		/// <param name="backbrush">Brush used to fill the background of the image. Can be <c>null</c>.</param>
		/// <param name="pixelformat">Specify the pixelformat here.</param>
		/// <param name="sourceDpiResolution">Resolution at which the graph document is rendered into a bitmap.</param>
		/// <param name="destinationDpiResolution">Resolution which is assigned to the bitmap. This determines the physical size of the bitmap.</param>
		/// <returns>The saved bitmap. You should call Dispose when you no longer need the bitmap.</returns>
		public static Bitmap RenderAsBitmap(this GraphDocument doc, BrushX backbrush, PixelFormat pixelformat, double sourceDpiResolution, double destinationDpiResolution)
		{
			return RenderAsBitmap(doc, backbrush, null, pixelformat, sourceDpiResolution, destinationDpiResolution);
		}
Beispiel #5
0
 /// <summary>
 /// Saves the graph as an bitmap file and returns the bitmap.
 /// </summary>
 /// <param name="doc">The graph document to export.</param>
 /// <param name="backbrush">Brush used to fill the background of the image. Can be <c>null</c>.</param>
 /// <param name="pixelformat">Specify the pixelformat here.</param>
 /// <param name="sourceDpiResolution">Resolution at which the graph document is rendered into a bitmap.</param>
 /// <param name="destinationDpiResolution">Resolution which is assigned to the bitmap. This determines the physical size of the bitmap.</param>
 /// <returns>The saved bitmap. You should call Dispose when you no longer need the bitmap.</returns>
 public static Bitmap RenderAsBitmap(this GraphDocument doc, Altaxo.Graph.Gdi.BrushX backbrush, PixelFormat pixelformat, double sourceDpiResolution, double destinationDpiResolution)
 {
     return(RenderAsBitmap(doc, backbrush, null, pixelformat, sourceDpiResolution, destinationDpiResolution));
 }
 public void InitializeFillColor(BrushX sel)
 {
   m_cbLineFillColor.Brush = sel;
 }
Beispiel #7
0
 protected void EhChooseTransparencyValue(object sender, EventArgs e)
 {
   ToolStripItem item = (ToolStripItem)sender;
   int alpha = (int)item.Tag;
   this.Brush = new BrushX(Color.FromArgb(alpha, this.Brush.Color));
   OnSelectedItemChanged(EventArgs.Empty);
   OnSelectedValueChanged(EventArgs.Empty);
   OnSelectionChangeCommitted(EventArgs.Empty);
 }
Beispiel #8
0
    void SetDataSource(BrushX selectedBrush)
    {
      Items.Clear();
      if (selectedBrush.BrushType == BrushType.SolidBrush)
        Items.Add(selectedBrush.Color);
      else
        Items.Add(selectedBrush);

      SelectedIndex = 0;
    }
Beispiel #9
0
		public virtual bool CopyFrom(object obj)
		{
			if (object.ReferenceEquals(this, obj))
				return true;

			var from = obj as GraphExportOptions;

			if (null != from)
			{
				this._imageFormat = from.ImageFormat;
				this._pixelFormat = from.PixelFormat;
				this._backgroundBrush = null == from._backgroundBrush ? null : from._backgroundBrush.Clone();
				this.SourceDpiResolution = from.SourceDpiResolution;
				this.DestinationDpiResolution = from.DestinationDpiResolution;
				return true;
			}

			return false;
		}
Beispiel #10
0
		public override void Run(GraphController ctrl)
		{
			using (var brush = new BrushX(NamedColors.White))
				ctrl.Doc.CopyToClipboardAsBitmap(300, brush, PixelFormat.Format24bppRgb);
		}
Beispiel #11
0
		/// <summary>
		/// Copies the properties of another instance to this instance.
		/// </summary>
		/// <param name="pen">the PenHolder object to copy</param>
		public void CopyFrom(PenX pen)
		{
			if (object.ReferenceEquals(this, pen))
				return;

			_SetPenVariable(null);

			this._configuredProperties = pen._configuredProperties;
			this._penType = pen.PenType;
			this._alignment = pen.Alignment;

			if (0 != (this._configuredProperties & Configured.Brush))
				this._brush = new BrushX(pen._brush);

			this._color = pen.Color;

			if (null != pen._compoundArray)
				this._compoundArray = (float[])pen.CompoundArray.Clone();
			else
				this._compoundArray = null;

			this._dashPattern = pen._dashPattern; // immutable
			this._dashCap = pen._dashCap;

			this._cachedDashStyle = pen._cachedDashStyle;

			if (null != pen._cachedDashPattern)
				this._cachedDashPattern = (float[])pen._cachedDashPattern.Clone();
			else
				this._cachedDashPattern = null;

			this._cachedDashOffset = pen._cachedDashOffset;

			this._endCap = pen.EndCap;
			this._lineJoin = pen.LineJoin;
			this._miterLimit = pen.MiterLimit;
			this._startCap = pen.StartCap;

			if (null != pen._transformation)
				this._transformation = pen.Transform.Clone();
			else
				this._transformation = null;

			this._width = pen.Width;

			// note: there is an problem with Pen.Clone() : if the Color of the pen
			// was set to a known color, the color of the cloned pen is the same, but no longer a known color
			// therefore we avoid the cloning of the pen here

			// if(m_CachedMode && null!=pen.m_Pen)
			//   _SetPenVariable( (Pen)pen.m_Pen.Clone() );
			// else
			//   _SetPenVariable(null);
		}
		/// <summary>
		/// Saves the graph as an bitmap file into the file <paramref name="filename"/> using the default
		/// pixel format 32bppArgb.
		/// </summary>
		/// <param name="doc">The graph document to export.</param>
		/// <param name="dpiResolution">Resolution of the bitmap in dpi. Determines the pixel size of the bitmap.</param>
		/// <param name="backbrush">Brush used to fill the background of the image. Can be <c>null</c>.</param>
		/// <param name="filename">The filename of the file to save the bitmap into.</param>
		public static Metafile RenderAsEnhancedMetafileVectorFormat(this GraphDocument doc, double dpiResolution, BrushX backbrush, string filename)
		{
			return RenderAsEnhancedMetafileVectorFormat(doc, dpiResolution, backbrush, PixelFormat.Format32bppArgb, filename);
		}
		/// <summary>
		/// Saves the graph as an bitmap file and returns the bitmap.
		/// </summary>
		/// <param name="doc">The graph document to export.</param>
		/// <param name="backbrush1">First brush used to fill the background of the image. Can be <c>null</c>.</param>
		/// <param name="backbrush2">Second brush used to fill the background of the image. Can be <c>null</c>.</param>
		/// <param name="pixelformat">Specify the pixelformat here.</param>
		/// <param name="sourceDpiResolution">Resolution at which the graph document is rendered into a bitmap.</param>
		/// <param name="destinationDpiResolution">Resolution which is assigned to the bitmap. This determines the physical size of the bitmap.</param>
		/// <returns>The saved bitmap. You should call Dispose when you no longer need the bitmap.</returns>
		public static Bitmap RenderAsBitmap(this GraphDocument doc, BrushX backbrush1, BrushX backbrush2, PixelFormat pixelformat, double sourceDpiResolution, double destinationDpiResolution)
		{
			// round the pixels to multiples of 4, many programs rely on this
			int bmpWidth = (int)(4 * Math.Ceiling(0.25 * doc.Size.X * sourceDpiResolution / 72));
			int bmpHeight = (int)(4 * Math.Ceiling(0.25 * doc.Size.Y * sourceDpiResolution / 72));
			System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(bmpWidth, bmpHeight, pixelformat);

			double outputScaling = sourceDpiResolution / destinationDpiResolution;
			bitmap.SetResolution((float)(bmpWidth / (outputScaling * doc.Size.X / 72)), (float)(bmpHeight / (outputScaling * doc.Size.Y / 72)));

			using (Graphics grfx = Graphics.FromImage(bitmap))
			{
				// Set everything to high quality
				grfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
				grfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

				// 2014-10-10 Setting InterpolationMode to HighQualityBicubic and PixelOffsetMode to HighQuality
				// causes problems when rendering small bitmaps (at a large magnification, for instance the density image legend):
				// the resulting image seems a litte soft, the colors somehow distorted, so I decided not to use them here any more

				//		grfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
				//		grfx.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

				grfx.PageUnit = GraphicsUnit.Point;
				grfx.ScaleTransform((float)outputScaling, (float)outputScaling);
				grfx.SetClip(new RectangleF(0, 0, (float)doc.Size.X, (float)doc.Size.Y));

				if (null != backbrush1)
				{
					backbrush1.SetEnvironment(new RectangleD2D(0, 0, doc.Size.X, doc.Size.Y), sourceDpiResolution);
					grfx.FillRectangle(backbrush1, new RectangleF(0, 0, (float)doc.Size.X, (float)doc.Size.Y));
				}

				if (null != backbrush2)
				{
					backbrush2.SetEnvironment(new RectangleD2D(0, 0, doc.Size.X, doc.Size.Y), sourceDpiResolution);
					grfx.FillRectangle(backbrush2, new RectangleF(0, 0, (float)doc.Size.X, (float)doc.Size.Y));
				}

#if DIAGNOSTICLINERENDERING
				{
					var fDocSizeX = (float)doc.Size.X;
					var fDocSizeY = (float)doc.Size.Y;
					grfx.DrawLine(Pens.Black, 0, 0, fDocSizeX * 2, fDocSizeY * 1.3f);

					grfx.DrawLine(Pens.Black, 0, 0, fDocSizeX, fDocSizeY);
					grfx.DrawLine(Pens.Black, 0, fDocSizeY, fDocSizeX, 0);
					grfx.DrawLine(Pens.Black, 0, 0, fDocSizeX / 4, fDocSizeY / 2);
					grfx.DrawLine(Pens.Black, 0, fDocSizeY, fDocSizeX / 4, fDocSizeY / 2);
					grfx.DrawLine(Pens.Black, fDocSizeX * 0.75f, fDocSizeY / 2, fDocSizeX, 0);
					grfx.DrawLine(Pens.Black, fDocSizeX * 0.75f, fDocSizeY / 2, fDocSizeX, fDocSizeY);
				}
#endif

				doc.Paint(grfx, true);
			}

			bitmap.SetResolution((float)destinationDpiResolution, (float)destinationDpiResolution);

			return bitmap;
		}
    /// <summary>
    /// Set the member variables to default values. Intended only for use in constructors and deserialization code.
    /// </summary>
    protected virtual void SetMemberVariablesToDefault()
    {
      m_NonPageAreaColor = Color.Gray;
    
      m_PageGroundBrush = new BrushX(Color.LightGray);

      m_PrintableAreaBrush = new BrushX(Color.Snow);

      m_HorizRes  = 300;
    
      m_VertRes = 300;

      m_Zoom  = 0.4f;
    
      // If true, the view is zoomed so that the page fits exactly into the viewing area.</summary>
      m_AutoZoom = true; // if true, the sheet is zoomed as big as possible to fit into window
    
    
      // Number of the currently selected layer (or -1 if no layer is present).</summary>
      m_CurrentLayerNumber = -1;
    
      // Number of the currently selected plot (or -1 if no plot is present on the layer).</summary>
      m_CurrentPlotNumber = -1;
    
      // Currently selected GraphTool.</summary>
      // m_CurrentGraphTool = GraphTools.ObjectPointer;
    
      // A instance of a mouse handler class that currently handles the mouse events..</summary>
      m_MouseState= new ObjectPointerMouseHandler(this);

      

      // This holds a frozen image of the graph during the moving time
      m_FrozenGraph=null;
    }
		public void UpdatePreview(BrushX brush)
		{
			if (null == _previewPanel || null == brush)
				return;

			int height = (int)_previewPanel.ActualHeight;
			int width = (int)_previewPanel.ActualWidth;
			if (height <= 0)
				height = 64;
			if (width <= 0)
				width = 64;

			if (null == _previewBitmap)
			{
				_previewBitmap = new GdiToWpfBitmap(width, height);
				_previewPanel.Source = _previewBitmap.WpfBitmap;
			}

			if (width != _previewBitmap.GdiRectangle.Width || height != _previewBitmap.GdiRectangle.Height)
			{
				_previewBitmap.Resize(width, height);
				_previewPanel.Source = _previewBitmap.WpfBitmap;
			}

			using (var grfx = _previewBitmap.BeginGdiPainting())
			{
				var fullRect = _previewBitmap.GdiRectangle;

				grfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
				grfx.FillRectangle(System.Drawing.Brushes.Transparent, fullRect);
				grfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

				var r2 = fullRect;
				r2.Inflate(-r2.Width / 4, -r2.Height / 4);
				//grfx.FillRectangle(System.Drawing.Brushes.Black, r2);

				brush.SetEnvironment(fullRect, BrushX.GetEffectiveMaximumResolution(grfx));
				grfx.FillRectangle(brush, fullRect);

				_previewBitmap.EndGdiPainting();
			}
		}
 public BrushControllerSimple(BrushX doc)
 {
   InitializeDocument(doc);
 }
 public BrushControllerAdvanced(BrushX doc)
   : base(doc)
 {
 }
 public bool Apply()
 {
   if (_doc != null || _view.Brush.IsVisible)
     _doc = _view.Brush;
   
   return true;
 }
Beispiel #19
0
		private void _SetBrushVariable(BrushX bh)
		{
			if (null != _brush)
				_brush.Dispose();

			_brush = bh;

			if (null != _brush)
				_brush.ParentObject = this;
		}
		/// <summary>
		/// Renders the graph document as bitmap with default PixelFormat.Format32bppArgb.
		/// </summary>
		/// <param name="doc">The graph document used.</param>
		/// <param name="exportOptions">The clipboard export options.</param>
		/// <param name="pixelFormat">The pixel format for the bitmap. Default is PixelFormat.Format32bppArgb.</param>
		/// <returns>The rendered enhanced metafile.</returns>
		public static Bitmap RenderAsBitmap(GraphDocument doc, EmbeddedObjectRenderingOptions exportOptions, PixelFormat pixelFormat = PixelFormat.Format32bppArgb)
		{
			BrushX opaqueGround = null;
			if (!GraphExportOptions.HasPixelFormatAlphaChannel(pixelFormat))
				opaqueGround = new BrushX(exportOptions.BackgroundColorForFormatsWithoutAlphaChannel);

			var result = RenderAsBitmap(doc, opaqueGround, exportOptions.BackgroundBrush, pixelFormat, exportOptions.SourceDpiResolution, exportOptions.SourceDpiResolution / exportOptions.OutputScalingFactor);

			if (null != opaqueGround)
				opaqueGround.Dispose();

			return result;
		}
		/// <summary>
		/// Saves the graph as an bitmap file into the stream <paramref name="stream"/>.
		/// </summary>
		/// <param name="doc">The graph document to export.</param>
		/// <param name="stream">The stream to save the metafile into.</param>
		/// <param name="imageFormat">The format of the destination image.</param>
		/// <param name="backbrush">Brush used to fill the background of the image. Can be <c>null</c>.</param>
		/// <param name="pixelformat">Specify the pixelformat here.</param>
		/// <param name="sourceDpiResolution">Resolution at which the graph is rendered to a bitmap.</param>
		/// <param name="destinationDpiResolution">Resolution of the resulting bitmap. This determines the physical size of the bitmap.</param>
		public static void RenderAsBitmapToStream(this GraphDocument doc, System.IO.Stream stream, System.Drawing.Imaging.ImageFormat imageFormat, BrushX backbrush, PixelFormat pixelformat, double sourceDpiResolution, double destinationDpiResolution)
		{
			System.Drawing.Bitmap bitmap = RenderAsBitmap(doc, backbrush, pixelformat, sourceDpiResolution, destinationDpiResolution);

			bitmap.Save(stream, imageFormat);

			bitmap.Dispose();
		}
		/// <summary>
		/// Saves the graph as an bitmap file into the stream using the default pixelformat 32bppArgb.<paramref name="stream"/>.
		/// </summary>
		/// <param name="doc">The graph document to export.</param>
		/// <param name="stream">The stream to save the metafile into.</param>
		/// <param name="imageFormat">The format of the destination image.</param>
		/// <param name="backbrush">Brush used to fill the background of the image. Can be <c>null</c>.</param>
		/// <param name="dpiResolution">Resolution of the bitmap in dpi. Determines the pixel size of the bitmap.</param>
		public static void RenderAsBitmapToStream(this GraphDocument doc, System.IO.Stream stream, System.Drawing.Imaging.ImageFormat imageFormat, BrushX backbrush, double dpiResolution)
		{
			RenderAsBitmapToStream(doc, stream, imageFormat, backbrush, PixelFormat.Format32bppArgb, dpiResolution, dpiResolution);
		}
Beispiel #23
0
    public ColumnStyle(ColumnStyle s)
    {
      _columnStyleType = s._columnStyleType;
      m_Size = s.m_Size;

      _isCellPenCustom = s._isCellPenCustom;
      m_CellPen = (PenX)s.m_CellPen.Clone();
      m_TextFormat = (StringFormat)s.m_TextFormat.Clone();
      m_TextFont = (Font)s.m_TextFont.Clone();
      
      _isTextBrushCustom = s._isTextBrushCustom;
      m_TextBrush = (BrushX)s.m_TextBrush.Clone();

      _isBackgroundBrushCustom = s._isBackgroundBrushCustom;
      m_BackgroundBrush = (BrushX)s.m_BackgroundBrush.Clone();
    }
		/// <summary>
		/// Saves the graph as an bitmap file into the file <paramref name="filename"/>.
		/// </summary>
		/// <param name="doc">The graph document to export.</param>
		/// <param name="filename">The filename of the file to save the bitmap into.</param>
		/// <param name="imageFormat">The format of the destination image.</param>
		/// <param name="backbrush">Brush used to fill the background of the image. Can be <c>null</c>.</param>
		/// <param name="pixelformat">Specify the pixelformat here.</param>
		/// <param name="sourceDpiResolution">Resolution in dpi used to render the graph into the bitmap.</param>
		/// <param name="destinationDpiResolution">Resolution that is set in the parameters of the bitmap. This determines the physical size of the bitmap.</param>
		public static void RenderAsBitmapToFile(this GraphDocument doc, string filename, System.Drawing.Imaging.ImageFormat imageFormat, BrushX backbrush, PixelFormat pixelformat, double sourceDpiResolution, double destinationDpiResolution)
		{
			using (System.IO.Stream str = new System.IO.FileStream(filename, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.Read))
			{
				RenderAsBitmapToStream(doc, str, imageFormat, backbrush, pixelformat, sourceDpiResolution, destinationDpiResolution);
				str.Close();
			}
		}
Beispiel #25
0
		public ColumnStyle(ColumnStyleType type)
		{
			_cellPen = new PenX(GdiColorHelper.ToNamedColor(SystemColors.InactiveBorder), 1) { ParentObject = this };
			_textBrush = new BrushX(GdiColorHelper.ToNamedColor(SystemColors.WindowText)) { ParentObject = this };
			_backgroundBrush = new BrushX(GdiColorHelper.ToNamedColor(SystemColors.Window)) { ParentObject = this };

			_columnStyleType = type;

			SetDefaultCellBorder();
			SetDefaultBackgroundBrush();
			SetDefaultTextBrush();
			SetDefaultTextFont();
		}
		/// <summary>
		/// Saves the graph as an bitmap file into the file <paramref name="filename"/> using the default
		/// pixel format 32bppArgb.
		/// </summary>
		/// <param name="doc">The graph document to export.</param>
		/// <param name="filename">The filename of the file to save the bitmap into.</param>
		/// <param name="imageFormat">The format of the destination image.</param>
		/// <param name="backbrush">Brush used to fill the background of the image. Can be <c>null</c>.</param>
		/// <param name="dpiResolution">Resolution of the bitmap in dpi. Determines the pixel size of the bitmap.</param>
		public static void RenderAsBitmapToFile(this GraphDocument doc, string filename, System.Drawing.Imaging.ImageFormat imageFormat, BrushX backbrush, double dpiResolution)
		{
			RenderAsBitmapToFile(doc, filename, imageFormat, backbrush, PixelFormat.Format32bppArgb, dpiResolution, dpiResolution);
		}
Beispiel #27
0
    protected void EhChooseCustomColor(object sender, EventArgs e)
    {
      if (null == _colorDialog)
        _colorDialog = new ColorDialog();

      _colorDialog.Color = this.Brush.Color;
      if (DialogResult.OK == _colorDialog.ShowDialog(this))
      {
        this.Brush = new BrushX(_colorDialog.Color);
        OnSelectedItemChanged(EventArgs.Empty);
        OnSelectedValueChanged(EventArgs.Empty);
        OnSelectionChangeCommitted(EventArgs.Empty);
      }
    }
		/// <summary>
		/// Renders the graph document as enhanced metafile in vector format.
		/// </summary>
		/// <param name="doc">graph document.</param>
		/// <param name="stream">The stream the metafile is rendered to.</param>
		/// <param name="sourceDpiResolution">The resolution in dpi of the source.</param>
		/// <param name="outputScalingFactor">Output scaling factor. If less than 1, the image will appear smaller than originally, if greater than 1, the image will appear larger than originally.</param>
		/// <param name="backgroundBrush">The background brush. This argument can be null, or the brush can be transparent.</param>
		/// <param name="pixelFormat">Optional: Only used if the graphics context can not be created from a printer document. Pixel format of the bitmap that is used in this case to construct the graphics context.</param>
		public static void RenderAsEnhancedMetafileVectorFormatToStream(GraphDocument doc, System.IO.Stream stream, double sourceDpiResolution, double outputScalingFactor, BrushX backgroundBrush = null, PixelFormat pixelFormat = PixelFormat.Format32bppArgb)
		{
			var renderingProc = new Action<Graphics>(
					(grfxMetafile) =>
					{
						if (backgroundBrush != null)
						{
							backgroundBrush.SetEnvironment(new RectangleD2D(0, 0, doc.Size.X, doc.Size.Y), sourceDpiResolution);
							grfxMetafile.FillRectangle(backgroundBrush, new RectangleF(0, 0, (float)doc.Size.X, (float)doc.Size.Y));
						}

#if DIAGNOSTICLINERENDERING
				{
					grfxMetafile.DrawLine(Pens.Black, 0, 0, fDocSizeX * 2, fDocSizeY * 1.3f);

					grfxMetafile.DrawLine(Pens.Black, 0, 0, fDocSizeX, fDocSizeY);
					grfxMetafile.DrawLine(Pens.Black, 0, fDocSizeY, fDocSizeX, 0);
					grfxMetafile.DrawLine(Pens.Black, 0, 0, fDocSizeX / 4, fDocSizeY / 2);
					grfxMetafile.DrawLine(Pens.Black, 0, fDocSizeY, fDocSizeX / 4, fDocSizeY / 2);
					grfxMetafile.DrawLine(Pens.Black, fDocSizeX * 0.75f, fDocSizeY / 2, fDocSizeX, 0);
					grfxMetafile.DrawLine(Pens.Black, fDocSizeX * 0.75f, fDocSizeY / 2, fDocSizeX, fDocSizeY);
				}
#endif

						doc.Paint(grfxMetafile, true);
					});

			RenderAsEnhancedMetafileToStream(renderingProc, stream, doc.Size, sourceDpiResolution, outputScalingFactor, pixelFormat);
		}
Beispiel #29
0
 public BrushColorComboBox(BrushX selectedBrush)
   : this()
 {
   SetDataSource(selectedBrush);
 }
		/// <summary>
		/// Renders the graph document as enhanced metafile in vector format.
		/// </summary>
		/// <param name="doc">graph document.</param>
		/// <param name="sourceDpiResolution">The resolution in dpi of the source.</param>
		/// <param name="outputScalingFactor">Output scaling factor. If less than 1, the image will appear smaller than originally, if greater than 1, the image will appear larger than originally.</param>
		/// <param name="backgroundBrush">The background brush. This argument can be null, or the brush can be transparent.</param>
		/// <param name="pixelFormat">Optional: Only used if the graphics context can not be created from a printer document. Pixel format of the bitmap that is used in this case to construct the graphics context.</param>
		/// <param name="stream">Optional: stream. If given, the metafile is rendered into the given stream.</param>
		/// <returns>The rendered enhanced metafile (vector format).</returns>
		public static Metafile RenderAsEnhancedMetafileVectorFormat(GraphDocument doc, double sourceDpiResolution, double outputScalingFactor, BrushX backgroundBrush = null, PixelFormat pixelFormat = PixelFormat.Format32bppArgb, System.IO.Stream stream = null)
		{
			var mystream = null != stream ? stream : new MemoryStream();
			try
			{
				RenderAsEnhancedMetafileVectorFormatToStream(doc, mystream, sourceDpiResolution, outputScalingFactor, backgroundBrush, pixelFormat);
				return new Metafile(mystream);
			}
			finally
			{
				if (null == stream) // only if stream is null, i.e. we had created a new Memorystream
					mystream.Dispose(); // we should dispose this MemoryStream
			}
		}
Beispiel #31
0
        /// <summary>
        /// Saves the graph as an bitmap file and returns the bitmap.
        /// </summary>
        /// <param name="doc">The graph document to export.</param>
        /// <param name="backbrush1">First brush used to fill the background of the image (normally used with 24bbp bitmap formats to make the background opaque. Can be <c>null</c>.</param>
        /// <param name="backbrush2">Second brush used to fill the background of the image. Can be <c>null</c>.</param>
        /// <param name="pixelformat">Specify the pixelformat here.</param>
        /// <param name="sourceDpiResolution">Resolution at which the graph document is rendered into a bitmap.</param>
        /// <param name="destinationDpiResolution">Resolution which is assigned to the bitmap. This determines the physical size of the bitmap.</param>
        /// <returns>The saved bitmap. You should call Dispose when you no longer need the bitmap.</returns>
        public static Bitmap RenderAsBitmap(this GraphDocument doc, Altaxo.Graph.Gdi.BrushX backbrush1, Altaxo.Graph.Gdi.BrushX backbrush2, PixelFormat pixelformat, double sourceDpiResolution, double destinationDpiResolution)
        {
            var imageExporter = Current.ProjectService.GetProjectItemImageExporter(doc);

            if (null == imageExporter)
            {
                return(null);
            }

            Bitmap bitmap = null;

            using (var memStream = new System.IO.MemoryStream())
            {
                var exportOptions = new Altaxo.Graph.Gdi.GraphExportOptions();
                exportOptions.TrySetImageAndPixelFormat(ImageFormat.Png, PixelFormat.Format32bppArgb);
                exportOptions.SourceDpiResolution      = sourceDpiResolution;
                exportOptions.DestinationDpiResolution = destinationDpiResolution;
                exportOptions.BackgroundBrush          = backbrush1;
                imageExporter.ExportAsImageToStream(doc, exportOptions, memStream);

                memStream.Seek(0, System.IO.SeekOrigin.Begin);
                bitmap = (Bitmap)Bitmap.FromStream(memStream);
            }

            int bmpWidth  = bitmap.Width;
            int bmpHeight = bitmap.Height;

            /*
             *                double outputScaling = sourceDpiResolution / destinationDpiResolution;
             *                bitmap.SetResolution((float)(bmpWidth / (outputScaling * doc.Size.X / 72)), (float)(bmpHeight / (outputScaling * doc.Size.Y / 72)));
             *
             *                using (Graphics grfx = Graphics.FromImage(bitmap))
             *                {
             *                        // Set everything to high quality
             *                        grfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
             *                        grfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
             *
             *                        // 2014-10-10 Setting InterpolationMode to HighQualityBicubic and PixelOffsetMode to HighQuality
             *                        // causes problems when rendering small bitmaps (at a large magnification, for instance the density image legend):
             *                        // the resulting image seems a litte soft, the colors somehow distorted, so I decided not to use them here any more
             *
             *                        //		grfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
             *                        //		grfx.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
             *
             *                        grfx.PageUnit = GraphicsUnit.Point;
             *                        grfx.ScaleTransform((float)outputScaling, (float)outputScaling);
             *                        grfx.SetClip(new RectangleF(0, 0, (float)doc.Size.X, (float)doc.Size.Y));
             *
             *                        if (null != backbrush1)
             *                        {
             *                                backbrush1.SetEnvironment(new RectangleD2D(0, 0, doc.Size.X, doc.Size.Y), sourceDpiResolution);
             *                                grfx.FillRectangle(backbrush1, new RectangleF(0, 0, (float)doc.Size.X, (float)doc.Size.Y));
             *                        }
             *
             *                        if (null != backbrush2)
             *                        {
             *                                backbrush2.SetEnvironment(new RectangleD2D(0, 0, doc.Size.X, doc.Size.Y), sourceDpiResolution);
             *                                grfx.FillRectangle(backbrush2, new RectangleF(0, 0, (float)doc.Size.X, (float)doc.Size.Y));
             *                        }
             *                }
             */

            bitmap.SetResolution((float)destinationDpiResolution, (float)destinationDpiResolution);

            return(bitmap);
        }
		/// <summary>
		/// Saves the graph as an bitmap file into the file <paramref name="filename"/>.
		/// </summary>
		/// <param name="doc">The graph document to export.</param>
		/// <param name="dpiResolution">Resolution of the bitmap in dpi. Determines the pixel size of the bitmap.</param>
		/// <param name="backbrush">Brush used to fill the background of the image. Can be <c>null</c>.</param>
		/// <param name="pixelformat">Specify the pixelformat here.</param>
		/// <param name="filename">The filename of the file to save the bitmap into.</param>
		public static Metafile RenderAsEnhancedMetafileVectorFormat(this GraphDocument doc, double dpiResolution, BrushX backbrush, PixelFormat pixelformat, string filename)
		{
			Metafile mf;
			using (System.IO.Stream str = new System.IO.FileStream(filename, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.Read))
			{
				mf = RenderAsEnhancedMetafileVectorFormat(doc, dpiResolution, 1, backbrush, pixelformat, str);
				str.Close();
			}
			return mf;
		}
Beispiel #33
0
        /// <summary>
        /// Saves the graph into a stream.
        /// </summary>
        /// <param name="doc">The graph document to export.</param>
        /// <param name="stream">The stream to render inot.</param>
        /// <param name="backbrush1">First brush used to fill the background of the image (normally used with 24bbp bitmap formats to make the background opaque. Can be <c>null</c>.</param>
        /// <param name="backbrush2">Second brush used to fill the background of the image. Can be <c>null</c>.</param>
        /// <param name="pixelformat">Specify the pixelformat here.</param>
        /// <param name="sourceDpiResolution">Resolution at which the graph document is rendered into a bitmap.</param>
        /// <param name="destinationDpiResolution">Resolution which is assigned to the bitmap. This determines the physical size of the bitmap.</param>
        /// <returns>The pixel dimensions of the image if the rendering was successful. The tuple (0,0) is returned if the rendering was unsuccessful, e.g. if no exporter was available.</returns>
        public static (int PixelsX, int PixelsY) RenderToStream(this GraphDocument doc, System.IO.Stream stream, Altaxo.Graph.Gdi.BrushX backbrush1, Altaxo.Graph.Gdi.BrushX backbrush2, PixelFormat pixelformat, double sourceDpiResolution, double destinationDpiResolution)
        {
            var exportOptions = new Altaxo.Graph.Gdi.GraphExportOptions();

            exportOptions.TrySetImageAndPixelFormat(ImageFormat.Png, PixelFormat.Format32bppArgb);
            exportOptions.SourceDpiResolution      = sourceDpiResolution;
            exportOptions.DestinationDpiResolution = destinationDpiResolution;
            exportOptions.BackgroundBrush          = backbrush1;
            return(RenderToStream(doc, stream, exportOptions));
        }
Beispiel #34
0
        }     // end of prop. Brush

        public static bool AreEqual(BrushX b1, BrushX b2)
        {
            if (b1._brushType != b2._brushType)
            {
                return(false);
            }

            // Brush types are equal - we have to go into details...
            switch (b1._brushType)
            {
            case BrushType.SolidBrush:
                if (b1._foreColor != b2._foreColor)
                {
                    return(false);
                }
                break;

            case BrushType.HatchBrush:
                if (b1._foreColor != b2._foreColor)
                {
                    return(false);
                }
                if (b1._backColor != b2._backColor)
                {
                    return(false);
                }
                if (b1._hatchStyle != b2._hatchStyle)
                {
                    return(false);
                }
                break;

            case BrushType.LinearGradientBrush:
                if (b1._foreColor != b2._foreColor)
                {
                    return(false);
                }
                if (b1._backColor != b2._backColor)
                {
                    return(false);
                }
                if (b1._gradientMode != b2._gradientMode)
                {
                    return(false);
                }
                if (b1._wrapMode != b2._wrapMode)
                {
                    return(false);
                }
                if (b1._gradientShape != b2._gradientShape)
                {
                    return(false);
                }
                break;

            case BrushType.PathGradientBrush:
                if (b1._foreColor != b2._foreColor)
                {
                    return(false);
                }
                if (b1._backColor != b2._backColor)
                {
                    return(false);
                }
                if (b1._wrapMode != b2._wrapMode)
                {
                    return(false);
                }
                break;

            case BrushType.TextureBrush:
                if (b1._wrapMode != b2._wrapMode)
                {
                    return(false);
                }
                if (b1._scale != b2._scale)
                {
                    return(false);
                }
                if (b1._textureImage.ToString() != b2._textureImage.ToString())
                {
                    return(false);
                }
                break;
            } // end of switch
            return(true);
        }