本文整理汇总了C#中System.Drawing.Size.ScaleToFitBounds方法的典型用法代码示例。如果您正苦于以下问题:C# Size.ScaleToFitBounds方法的具体用法?C# Size.ScaleToFitBounds怎么用?C# Size.ScaleToFitBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Size
的用法示例。
在下文中一共展示了Size.ScaleToFitBounds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScaleToFitBounds_Tall
public void ScaleToFitBounds_Tall()
{
Size real = new Size(120, 200);
Size limit = new Size(120, 100);
Size result = new Size(60, 100);
Assert.AreEqual(result, real.ScaleToFitBounds(limit));
}
示例2: ScaleToFitBounds_Wide
public void ScaleToFitBounds_Wide()
{
Size real = new Size(240, 100);
Size limit = new Size(120, 100);
Size result = new Size(120, 50);
Assert.AreEqual(result, real.ScaleToFitBounds(limit));
}
示例3: RenderPageCore
Bitmap RenderPageCore(int pageNum, Size maxSize, RenderQuality quality)
{
ArgCheck.InRange(pageNum, 0, PageCount, "pageNum");
_pdfDoc.o.CurrentPage = pageNum;
_pdfDoc.o.UseMuPDF = false;
if (_pdfDoc.o.SupportsMuPDF && quality == RenderQuality.HighQuality)
{
_pdfDoc.o.UseMuPDF = true;
}
// Scale
Size pageSize = new Size(_pdfDoc.o.PageWidth, _pdfDoc.o.PageHeight);
Size size = pageSize.ScaleToFitBounds(maxSize);
// 24bpp format for compatibility with AForge
Bitmap bitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb);
using (Graphics g = Graphics.FromImage(bitmap))
{
_pdfDoc.o.Zoom = ZoomConst * (double)bitmap.Width / _pdfDoc.o.PageWidth;
try
{
// Note: not certain what the params mean.
// Simple RenderPage sometimes does not zoom properly
_pdfDoc.o.RenderPage(g.GetHdc(), true, false);
g.ReleaseHdc();
}
finally
{
_pdfDoc.o.Zoom = ZoomConst;
}
Rectangle bounds = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
g.FillRectangle(Brushes.White, bounds);
_pdfDoc.o.ClientBounds = bounds;
_pdfDoc.o.DrawPageHDC(g.GetHdc());
g.ReleaseHdc();
}
return bitmap;
}