本文整理汇总了C#中Area.Fit方法的典型用法代码示例。如果您正苦于以下问题:C# Area.Fit方法的具体用法?C# Area.Fit怎么用?C# Area.Fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Area
的用法示例。
在下文中一共展示了Area.Fit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetImage
/// <summary>
/// Draw the current mathml equation to an image object.
/// </summary>
/// <param name="type">The type of image to return, currently this can be
/// either Bitmap or Metafile</param>
/// <param name="gr">The graphics context in which this bitmap should be created.</param>
/// <returns>A new image, null if an invalid type is given or there is no current element</returns>
public Image GetImage(Type type, Graphics gr)
{
if (mathElement == null)
return null;
gr.PageUnit = GraphicsUnit.Pixel;
// build the formatting tree
MathMLFormatter formatter = new MathMLFormatter();
WinFormattingContext ctx = new WinFormattingContext(gr, fontSize);
format = formatter.Format(mathElement, ctx);
// build the are tree
box = format.BoundingBox;
area = format.Fit(box);
Image image = null;
int height = (int)Math.Ceiling(2+box.VerticalExtent);
int width = (int)Math.Ceiling(2+box.HorizontalExtent);
if(type.Equals(typeof(Bitmap)))
{
image = new Bitmap(width, height);
}
else if(type.Equals(typeof(Metafile)))
{
IntPtr dc = gr.GetHdc();
image = new Metafile(new MemoryStream(), dc, EmfType.EmfOnly);
gr.ReleaseHdc(dc);
}
if(image != null && area != null)
{
using (Graphics gi = Graphics.FromImage(image))
{
gi.PageUnit = GraphicsUnit.Pixel;
gi.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
DrawWithoutFormatting(gi, width, height, 1, 1);
}
}
return image;
}