本文整理汇总了C#中Cairo.DrawPixbufRect方法的典型用法代码示例。如果您正苦于以下问题:C# Cairo.DrawPixbufRect方法的具体用法?C# Cairo.DrawPixbufRect怎么用?C# Cairo.DrawPixbufRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cairo
的用法示例。
在下文中一共展示了Cairo.DrawPixbufRect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawImageSized
private void DrawImageSized(PageImage pi, Gdk.Pixbuf im, Cairo.Context g, Cairo.Rectangle r)
{
double height, width; // some work variables
StyleInfo si = pi.SI;
// adjust drawing rectangle based on padding
// System.Drawing.RectangleF r2 = new System.Drawing.RectangleF(r.Left + PixelsX(si.PaddingLeft),
// r.Top + PixelsY(si.PaddingTop),
// r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
// r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));
Cairo.Rectangle r2 = new Cairo.Rectangle(r.X + PixelsX(si.PaddingLeft),
r.Y + PixelsY(si.PaddingTop),
r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));
Cairo.Rectangle ir; // int work rectangle
switch (pi.Sizing)
{
case ImageSizingEnum.AutoSize:
// // Note: GDI+ will stretch an image when you only provide
// // the left/top coordinates. This seems pretty stupid since
// // it results in the image being out of focus even though
// // you don't want the image resized.
// if (g.DpiX == im.HorizontalResolution &&
// g.DpiY == im.VerticalResolution)
float imwidth = PixelsX(im.Width);
float imheight = PixelsX(im.Height);
ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
imwidth, imheight);
// else
// ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
// Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
//g.DrawImage(im, ir);
im = im.ScaleSimple((int)r2.Width, (int)r2.Height, Gdk.InterpType.Hyper);
g.DrawPixbufRect(im, ir);
break;
case ImageSizingEnum.Clip:
// Region saveRegion = g.Clip;
g.Save();
// Region clipRegion = new Region(g.Clip.GetRegionData());
// clipRegion.Intersect(r2);
// g.Clip = clipRegion;
g.Rectangle(r2);
g.Clip();
// if (dpiX == im.HorizontalResolution &&
// dpiY == im.VerticalResolution)
ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
im.Width, im.Height);
// else
// ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
// Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
// g.DrawImage(im, ir);
g.DrawPixbufRect(im, ir);
// g.Clip = saveRegion;
g.Restore();
break;
case ImageSizingEnum.FitProportional:
double ratioIm = (float)im.Height / (float)im.Width;
double ratioR = r2.Height / r2.Width;
height = r2.Height;
width = r2.Width;
if (ratioIm > ratioR)
{
// this means the rectangle width must be corrected
width = height * (1 / ratioIm);
}
else if (ratioIm < ratioR)
{
// this means the ractangle height must be corrected
height = width * ratioIm;
}
r2 = new Cairo.Rectangle(r2.X, r2.Y, width, height);
g.DrawPixbufRect(im, r2);
break;
case ImageSizingEnum.Fit:
default:
g.DrawPixbufRect(im, r2);
break;
}
}