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


C# CGBitmapContext.SetGrayFillColor方法代码示例

本文整理汇总了C#中CGBitmapContext.SetGrayFillColor方法的典型用法代码示例。如果您正苦于以下问题:C# CGBitmapContext.SetGrayFillColor方法的具体用法?C# CGBitmapContext.SetGrayFillColor怎么用?C# CGBitmapContext.SetGrayFillColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CGBitmapContext的用法示例。


在下文中一共展示了CGBitmapContext.SetGrayFillColor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddImageReflection

        public static UIImage AddImageReflection(UIImage image, float reflectionFraction)
        {
            int reflectionHeight = (int) (image.Size.Height * reflectionFraction);

            // Create a 2 bit CGImage containing a gradient that will be used for masking the
            // main view content to create the 'fade' of the reflection.  The CGImageCreateWithMask
            // function will stretch the bitmap image as required, so we can create a 1 pixel wide gradient

            // gradient is always black and white and the mask must be in the gray colorspace
            var colorSpace = CGColorSpace.CreateDeviceGray ();

            // Creat the bitmap context
            var gradientBitmapContext = new CGBitmapContext (IntPtr.Zero, 1, reflectionHeight, 8, 0, colorSpace, CGImageAlphaInfo.None);

            // define the start and end grayscale values (with the alpha, even though
            // our bitmap context doesn't support alpha the gradien requires it)
            float [] colors = { 0, 1, 1, 1 };

            // Create the CGGradient and then release the gray color space
            var grayScaleGradient = new CGGradient (colorSpace, colors, null);
            colorSpace.Dispose ();

            // create the start and end points for the gradient vector (straight down)
            var gradientStartPoint = new PointF (0, reflectionHeight);
            var gradientEndPoint = PointF.Empty;

            // draw the gradient into the gray bitmap context
            gradientBitmapContext.DrawLinearGradient (grayScaleGradient, gradientStartPoint,
                                                      gradientEndPoint, CGGradientDrawingOptions.DrawsAfterEndLocation);
            grayScaleGradient.Dispose ();

            // Add a black fill with 50% opactiy
            gradientBitmapContext.SetGrayFillColor (0, 0.5f);
            gradientBitmapContext.FillRect (new RectangleF (0, 0, 1, reflectionHeight));

            // conver the context into a CGImage and release the context
            var gradientImageMask = gradientBitmapContext.ToImage ();
            gradientBitmapContext.Dispose ();

            // create an image by masking the bitmap of the mainView content with the gradient view
            // then release the pre-masked content bitmap and the gradient bitmap
            var reflectionImage = image.CGImage.WithMask (gradientImageMask);
            gradientImageMask.Dispose ();

            var size = new SizeF (image.Size.Width, image.Size.Height + reflectionHeight);

            UIGraphics.BeginImageContext (size);
            image.Draw (PointF.Empty);
            var context = UIGraphics.GetCurrentContext ();
            context.DrawImage (new RectangleF (0, image.Size.Height, image.Size.Width, reflectionHeight), reflectionImage);

            var result = UIGraphics.GetImageFromCurrentImageContext ();
            UIGraphics.EndImageContext ();
            reflectionImage.Dispose ();

            return result;
        }
开发者ID:Ryohei-Yoshikawa,项目名称:OpenFlowSharp,代码行数:57,代码来源:ImageUtils.cs

示例2: Texture2D

        public Texture2D(string text, SizeF dim, UITextAlignment alignment, string fontName, float fontSize)
        {
            UIFont font = UIFont.FromName(fontName, fontSize);

            int width = (int)dim.Width;
            if (width != 1 && (width & (width - 1)) != 0) {
                int i = 1;
                while (i < width) {
                    i *= 2;
                }

                width = i;
            }

            int height = (int)dim.Height;
            if (height != 1 && (height & (height - 1)) != 0) {
                int i = 1;
                while (i < height) {
                    i *= 2;
                }
                height = i;
            }

            CGColorSpace colorSpace = CGColorSpace.CreateDeviceGray();

            byte[] data = new byte[width * height];

            unsafe {
                fixed (byte* dataPb = data) {
                    using (CGContext context = new CGBitmapContext((IntPtr)dataPb, width, height, 8, width, colorSpace, CGImageAlphaInfo.None)) {
                        context.SetGrayFillColor(1f, 1f);
                        context.TranslateCTM(0f, height);
                        context.ScaleCTM(1f, -1f);
                        UIGraphics.PushContext(context);
                        text.DrawInRect(new RectangleF(0, 0, dim.Width, dim.Height), font, UILineBreakMode.WordWrap, alignment);
                        UIGraphics.PopContext();
                    }
                }
            }
            colorSpace.Dispose();

            InitWithData(data, Texture2DPixelFormat.A8, width, height, dim);
        }
开发者ID:hcxyzlm,项目名称:CocosNet-1,代码行数:43,代码来源:Texture2D.cs


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