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


C# CGGradient.Dispose方法代码示例

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


在下文中一共展示了CGGradient.Dispose方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Draw

            public override void Draw(CGRect rect)
            {
                base.Draw(rect);

                var context = UIGraphics.GetCurrentContext();
                var colorSpace = CGColorSpace.CreateDeviceRGB();
                nfloat[] locations = { 0, 1 };

                CGColor[] colors =
                {
                    UIColor.FromRGB(0x8D, 0xCF, 0x16).CGColor,
                    UIColor.FromRGB(0x65, 0xBD, 0x10).CGColor,
                };

                var gradiend = new CGGradient(colorSpace, colors, locations);
                context.DrawLinearGradient(gradiend, new CGPoint(0, 0), new CGPoint(0, rect.Size.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
                gradiend.Dispose();
                colorSpace.Dispose();
            }
开发者ID:zdd910,项目名称:CodeHub,代码行数:19,代码来源:ProgressBarView.cs

示例3: Draw

        public override void Draw(RectangleF rect)
        {
            if (this.SplitViewController.DividerStyle == DIVIDER_STYLE.Thin)
            {
                base.Draw(rect);
            }
            else if (this.SplitViewController.DividerStyle == DIVIDER_STYLE.PaneSplitter)
            {
                // Draw gradient background.
                RectangleF oBounds = this.Bounds;
                CGColorSpace oRGB = CGColorSpace.CreateDeviceRGB();
                float[] aLocations = new float[] {0, 1};
                float[] aComponents = new float[]
                {
                    // light
                    0.988f, 0.988f, 0.988f, 1.0f,
                    // dark
                    0.875f, 0.875f, 0.875f, 1.0f
                };
                CGGradient oGradient = new CGGradient(oRGB, aComponents, aLocations);
                CGContext oContext = UIGraphics.GetCurrentContext();
                PointF oStart;
                PointF oEnd;
                if (this.SplitViewController.IsVertical)
                {
                    // Light left to dark right.
                    oStart = new PointF(oBounds.GetMinX(), oBounds.GetMidY());
                    oEnd = new PointF(oBounds.GetMaxX(), oBounds.GetMidY());
                }
                else
                {
                    // Light top to dark bottom.
                    oStart = new PointF(oBounds.GetMidX(), oBounds.GetMinY());
                    oEnd = new PointF(oBounds.GetMidX(), oBounds.GetMaxY());
                }
                oContext.DrawLinearGradient(oGradient, oStart, oEnd, CGGradientDrawingOptions.DrawsAfterEndLocation);
                oRGB.Dispose();
                oGradient.Dispose();

                // Draw borders.
                float fBorderThickness = 1.0f;
                UIColor.FromWhiteAlpha(0.7f, 1.0f).SetFill();
                UIColor.FromWhiteAlpha(0.7f, 1.0f).SetStroke();
                RectangleF oBorderRect = oBounds;
                if (this.SplitViewController.IsVertical)
                {
                    oBorderRect.Width = fBorderThickness;
                    UIGraphics.RectFill(oBorderRect);
                    oBorderRect.X = oBounds.GetMaxX() - fBorderThickness;
                    UIGraphics.RectFill(oBorderRect);
                }
                else
                {
                    oBorderRect.Height = fBorderThickness;
                    UIGraphics.RectFill(oBorderRect);
                    oBorderRect.Y = oBounds.GetMaxY() - fBorderThickness;
                    UIGraphics.RectFill(oBorderRect);
                }

                // Draw grip.
                this.DrawGripThumbInRect(oBounds);
            }
        }
开发者ID:robert-j,项目名称:MTSplitViewController,代码行数:63,代码来源:MTSplitDividerView.cs

示例4: Draw

        //(void)drawLayer:(CALayer *)theLayer inContext:(CGContextRef)theContext
        public override void Draw(RectangleF rect)
        {
            CGContext theContext = UIGraphics.GetCurrentContext();

            // Note: due to use of kCGEncodingMacRoman, this code only works with Roman alphabets!
            // In order to support non-Roman alphabets, you need to add code generate glyphs,
            // and use CGContextShowGlyphsAtPoint
            theContext.SelectFont(this.Font.Name, this.Font.PointSize, CGTextEncoding.MacRoman);

            // Set Text Matrix
            theContext.TextMatrix = new CGAffineTransform(1, 0, 0, -1, 0, 0);

            // Set Drawing Mode to clipping path, to clip the gradient created below
            theContext.SetTextDrawingMode (CGTextDrawingMode.Clip);

            // Draw the label's text
            string text = this.Text;// cStringUsingEncoding:NSMacOSRomanStringEncoding];
            theContext.ShowTextAtPoint(0, this.Font.Ascender, text, text.Length);

            // Calculate text width
            PointF textEnd = theContext.TextPosition;

            // Get the foreground text color from the UILabel.
            // Note: UIColor color space may be either monochrome or RGB.
            // If monochrome, there are 2 components, including alpha.
            // If RGB, there are 4 components, including alpha.
            CGColor textColor = this.TextColor.CGColor;
            float[] components = textColor.Components;
            int numberOfComponents = textColor.NumberOfComponents;
            bool isRGB = (numberOfComponents == 4);
            float red = components[0];
            float green = isRGB ? components[1] : components[0];
            float blue = isRGB ? components[2] : components[0];
            float alpha = isRGB ? components[3] : components[1];

            // The gradient has 4 sections, whose relative positions are defined by
            // the "gradientLocations" array:
            // 1) from 0.0 to gradientLocations[0] (dim)
            // 2) from gradientLocations[0] to gradientLocations[1] (increasing brightness)
            // 3) from gradientLocations[1] to gradientLocations[2] (decreasing brightness)
            // 4) from gradientLocations[3] to 1.0 (dim)
            int num_locations = 3;

            // The gradientComponents array is a 4 x 3 matrix. Each row of the matrix
            // defines the R, G, B, and alpha values to be used by the corresponding
            // element of the gradientLocations array
            float[] gradientComponents = new float[12];
            for (int row = 0; row < num_locations; row++)
            {
                int index = 4 * row;
                gradientComponents[index++] = red;
                gradientComponents[index++] = green;
                gradientComponents[index++] = blue;
                gradientComponents[index] = alpha * MBSliderView.gradientDimAlpha;
            }

            // If animating, set the center of the gradient to be bright (maximum alpha)
            // Otherwise it stays dim (as set above) leaving the text at uniform
            // dim brightness
            if (animationTimer != null)
            {
                gradientComponents[7] = alpha;
            }

            // Load RGB Colorspace
            CGColorSpace colorspace = CGColorSpace.CreateDeviceRGB();

            // Create Gradient
            CGGradient gradient = new CGGradient(colorspace, gradientComponents, gradientLocations);
            // Draw the gradient (using label text as the clipping path)
            theContext.DrawLinearGradient (gradient, this.Bounds.Location, textEnd, 0);

            // Cleanup
            gradient.Dispose();
            colorspace.Dispose();
        }
开发者ID:RTodorov,项目名称:MBSliderView-Xamarin-iOS,代码行数:77,代码来源:MBSliderLabel.cs

示例5: Draw

            public override void Draw(RectangleF rect)
            {
                var context = UIGraphics.GetCurrentContext();

                context.SaveState();
                var frame = rect;
                frame.X = (frame.Width - diameter) / 2;
                frame.Y = frame.Height / 2;
                frame.Height = diameter;
                frame.Width = diameter;

                //context.SetFillColorWithColor(UIColor.Black.ColorWithAlpha(.7f).CGColor);
                //context.FillEllipseInRect(frame);

                frame.Y -= 3;
                context.SetFillColorWithColor(UIColor.White.CGColor);
                context.FillRect(rect);
                context.SetFillColorWithColor(Color.CGColor);
                context.FillEllipseInRect(frame);

                context.RestoreState();

                //
                var shineFrame = frame;
                shineFrame.Height = (shineFrame.Height / 2);

                // the colors
                var topColor = UIColor.White.ColorWithAlpha(0.5f).CGColor;
                var bottomColor = UIColor.White.ColorWithAlpha(0.10f).CGColor;
                List<float> colors = new List<float>();
                colors.AddRange(topColor.Components);
                colors.AddRange(bottomColor.Components);
                float[] locations = new float[] { 0, 1 };

                CGGradient gradient = new CGGradient(topColor.ColorSpace, colors.ToArray(), locations);

                context.SaveState();
                context.SetShouldAntialias(true);
                context.AddEllipseInRect(shineFrame);
                context.Clip();

                var startPoint = new PointF(shineFrame.GetMidX(), shineFrame.GetMidY());
                var endPoint = new PointF(shineFrame.GetMidX(), shineFrame.GetMaxY());

                context.DrawLinearGradient(gradient, startPoint, endPoint, CGGradientDrawingOptions.DrawsBeforeStartLocation);
                gradient.Dispose();
                context.RestoreState();
            }
开发者ID:yolpsoftware,项目名称:UICalendar,代码行数:48,代码来源:CustomElements.cs

示例6: Draw

        public override void Draw(CGRect rect)
        {
            //Stopwatch s = new Stopwatch();
            //s.Start();

            //Console.WriteLine (" ----- SatBrightPickerView Draw");

            CGContext context = UIGraphics.GetCurrentContext ();

            CGColor[] gradColors = new CGColor[] {UIColor.FromHSBA(hue,1,1,1).CGColor,new CGColor(1,1,1,1)};
            nfloat[] gradLocations = new nfloat[] { 0.0f, 1.0f };

            var colorSpace = CGColorSpace.CreateDeviceRGB ();

            CGGradient gradient = new CGGradient (colorSpace, gradColors, gradLocations);
             context.DrawLinearGradient(gradient,new CGPoint(rect.Size.Width,0),new CGPoint(0,0),CGGradientDrawingOptions.DrawsBeforeStartLocation);

            gradColors = new CGColor[] {new CGColor(0,0,0,0), new CGColor(0,0,0,1)};

            gradient = new CGGradient(colorSpace,gradColors, gradLocations);
             context.DrawLinearGradient(gradient,new CGPoint(0,0),new CGPoint(0,rect.Size.Height),CGGradientDrawingOptions.DrawsBeforeStartLocation);

            gradient.Dispose();
            colorSpace.Dispose();

            //s.Stop();
            //Console.WriteLine("-----> SatBright Draw time: " + s.Elapsed.ToString());
        }
开发者ID:mubold,项目名称:AdvancedColorPicker,代码行数:28,代码来源:SaturationBrightnessPickerView.cs

示例7: Draw

        public override void Draw(RectangleF rect)
        {
            base.Draw (rect);

            CGContext context = UIGraphics.GetCurrentContext();

            CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();

            float step=0.166666666666667f;

            float[] locations = new float[] {
                0.00f,
                step,
                step*2,
                step*3,
                step*4,
                step*5,
                1.0f
            };

            CGColor c1 = new CGColor(1,0,1,1);
            CGColor c2 = new CGColor(1,1,0,1);
            CGColor c3 = new CGColor(0,1,1,1);

            CGColor[] colors = new CGColor[] {
                UIColor.Red.CGColor,
                c1,
                UIColor.Blue.CGColor,
                c3,
                UIColor.Green.CGColor,
                c2,
                UIColor.Red.CGColor
            };

            CGGradient gradiend = new CGGradient(colorSpace,colors, locations);
            context.DrawLinearGradient(gradiend,new PointF(rect.Size.Width,0),new PointF(0,0),CGGradientDrawingOptions.DrawsBeforeStartLocation);
            gradiend.Dispose();
            colorSpace.Dispose();
        }
开发者ID:YiannisBourkelis,项目名称:AdvancedColorPicker,代码行数:39,代码来源:HuePickerView.cs

示例8: DrawInContext

        public override void DrawInContext(CoreGraphics.CGContext ctx)
        {
            base.DrawInContext (ctx);

            var knobFrame = CGRect.Inflate(PaintFrame, -2.0f, -2.0f);

            UIBezierPath knobPath = UIBezierPath.FromRoundedRect((CGRect)knobFrame, (nfloat)knobFrame.Height * Slider.Curvaceousness / 2.0f);

            // 1) fill - with a subtle shadow
            ctx.SetShadow(new CGSize(0, 1), 1.0f, UIColor.Gray.CGColor);
            ctx.SetFillColor( Slider.KnobColor.CGColor);
            ctx.AddPath( knobPath.CGPath);
            ctx.FillPath ();

            // 2) outline
            ctx.SetStrokeColor(UIColor.Gray.CGColor);
            ctx.SetLineWidth((nfloat)0.5f);
            ctx.AddPath(knobPath.CGPath);
            ctx.StrokePath ();

            // 3) inner gradient
            var rect = CGRect.Inflate(knobFrame, -2.0f, -2.0f);
            var clipPath = UIBezierPath.FromRoundedRect ((CGRect)rect, (nfloat)rect.Height * Slider.Curvaceousness / 2.0f);

            CGGradient myGradient;
            CGColorSpace myColorspace;

            nfloat[] locations = { 0.0f, 1.0f };
            nfloat[] components = { 0.0f, 0.0f, 0.0f , 0.15f,  // Start color
                0.0f, 0.0f, 0.0f, 0.05f }; // End color

            myColorspace = CGColorSpace.CreateDeviceRGB (); // CGColorSpaceCreateDeviceRGB();
            myGradient = new CGGradient( myColorspace, components, locations);

            CGPoint startPoint = new CGPoint((float)rect.GetMidX(), (float)rect.GetMinY());
            CGPoint endPoint = new CGPoint((float)rect.GetMidX(), (float)rect.GetMaxY());

            ctx.SaveState ();
            ctx.AddPath( clipPath.CGPath);
            ctx.Clip ();
            ctx.DrawLinearGradient( (CGGradient)myGradient, (CGPoint)startPoint, (CGPoint)endPoint, (CGGradientDrawingOptions)0);

            myGradient.Dispose ();
            myColorspace.Dispose();
            ctx.RestoreState();

            // 4) highlight
            if (Highlighted)
            {
                // fill
                ctx.SetFillColor(UIColor.FromWhiteAlpha((nfloat)0.0f, (nfloat)0.1f).CGColor);
                ctx.AddPath( knobPath.CGPath);
                ctx.FillPath();
            }
        }
开发者ID:jasallen,项目名称:FuRangeSlider,代码行数:55,代码来源:FuRangeSliderKnobLayer.cs

示例9: Draw

        public override void Draw(RectangleF rect)
        {
            CGContext context = UIGraphics.GetCurrentContext();

            switch (this.mask) {
                case SVProgressHUDMask.Black : {
                    UIColor.FromWhiteAlpha(0f, 0.5f).SetColor();
                    context.FillRect(this.Bounds);
                    break;
                }
                case SVProgressHUDMask.Gradient: {
                    float[] locations = new float[2] {0.0f, 1.0f};
                    float[] colors = new float[8] {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f};
                    CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
                    CGGradient gradient = new CGGradient(colorSpace, colors, locations);
                    colorSpace.Dispose();

                    PointF center = new PointF(this.Bounds.Size.Width/2f, this.Bounds.Size.Height/2f);
                    float radius = Math.Min(this.Bounds.Size.Width, this.Bounds.Size.Height);
                    context.DrawRadialGradient(gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation);
                    gradient.Dispose();
                    break;
                }
            }
        }
开发者ID:cmckeegan,项目名称:SVProgressHUD,代码行数:25,代码来源:SVProgressHUD.cs

示例10: gradientImageWithSize

        private UIImage gradientImageWithSize(SizeF size, float[] locations, float[] components, int count)
        {
            UIGraphics.BeginImageContextWithOptions(size, false, 0);
            CGContext context = UIGraphics.GetCurrentContext();

            CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
            CGGradient colorGradient = new CGGradient(colorSpace, components, locations);
            colorSpace.Dispose();
            context.DrawLinearGradient(colorGradient, new PointF(0, 0), new PointF(size.Width, 0), 0);
            colorGradient.Dispose();

            UIImage image = UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();
            return image;
        }
开发者ID:jivkopetiov,项目名称:StackApp,代码行数:15,代码来源:KxMenu.cs


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