当前位置: 首页>>代码示例>>C#>>正文


C# Cairo.DrawPixbufRect方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:myersBR,项目名称:My-FyiReporting,代码行数:81,代码来源:RenderCairo.cs


注:本文中的Cairo.DrawPixbufRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。