本文整理汇总了C#中CGGradient类的典型用法代码示例。如果您正苦于以下问题:C# CGGradient类的具体用法?C# CGGradient怎么用?C# CGGradient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CGGradient类属于命名空间,在下文中一共展示了CGGradient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Draw
//Generated with PaintCode 2.2
public override void Draw(CGRect rect)
{
base.Draw(rect);
// General Declarations
var colorSpace = CGColorSpace.CreateDeviceRGB();
var context = UIGraphics.GetCurrentContext();
// Color Declarations
var darkBlue = UIColor.FromRGBA(0.053f, 0.123f, 0.198f, 1.000f);
var lightBlue = UIColor.FromRGBA(0.191f, 0.619f, 0.845f, 1.000f);
// Gradient Declarations
var backgroundGradientColors = new CGColor [] {lightBlue.CGColor, darkBlue.CGColor};
var backgroundGradientLocations = new nfloat [] {0.0f, 1.0f};
var backgroundGradient = new CGGradient(colorSpace, backgroundGradientColors, backgroundGradientLocations);
// Rectangle Drawing
var rectangleRect = new CGRect(rect.GetMinX() + (float)Math.Floor(rect.Width * -0.12917f + 0.5f), rect.GetMinY() + (float)Math.Floor(rect.Height * 0.00000f + 0.5f), (float)Math.Floor(rect.Width * 1.00000f + 0.5f) - (float)Math.Floor(rect.Width * -0.12917f + 0.5f), (float)Math.Floor(rect.Height * 1.00000f + 0.5f) - (float)Math.Floor(rect.Height * 0.00000f + 0.5f));
var rectanglePath = UIBezierPath.FromRect(rectangleRect);
context.SaveState();
rectanglePath.AddClip();
context.DrawLinearGradient(backgroundGradient,
new PointF((float)rectangleRect.GetMidX(), (float)rectangleRect.GetMinY()),
new PointF((float)rectangleRect.GetMidX(), (float)rectangleRect.GetMaxY()),
0);
context.RestoreState();
}
开发者ID:magicdukeman,项目名称:Giannios_John_Portfolio,代码行数:29,代码来源:BackgroundView.cs
示例2: Renderer_Element_SizeChanged
void Renderer_Element_SizeChanged(object sender, EventArgs e)
{
var element = sender as GradientView;
if (element == null)
return;
var bounds = element.Bounds;
var rect = new CGRect(bounds.X, bounds.Y, bounds.Width, bounds.Height);
UIGraphics.BeginImageContext(rect.Size);
using (CGContext g = UIGraphics.GetCurrentContext())
{
using (var rgb = CGColorSpace.CreateDeviceRGB())
{
nfloat[] colors = GetFloatArrayFromColors(element.StartColor, element.EndColor);
var gradient = new CGGradient(rgb, colors, null);
g.DrawRadialGradient(gradient, new CGPoint(0, 0), new nfloat(0), new CGPoint(100, 100), new nfloat(1000), CGGradientDrawingOptions.None);
}
using (var im = UIGraphics.GetImageFromCurrentImageContext())
using (var imageHolder = new UIImageView(im))
Container.AddSubview(imageHolder);
UIGraphics.EndImageContext();
}
}
开发者ID:antixaker,项目名称:GradientTestApp,代码行数:29,代码来源:GradientEffect.cs
示例3: MakeBlueSea
public static UIImage MakeBlueSea()
{
UIGraphics.BeginImageContext(new System.Drawing.SizeF(640,1136));
//BEGIN PAINTCODE
//// General Declarations
var colorSpace = CGColorSpace.CreateDeviceRGB();
var context = UIGraphics.GetCurrentContext();
//// Color Declarations
UIColor color = UIColor.FromRGBA(0.114f, 0.705f, 1.000f, 1.000f);
UIColor gradientColor = UIColor.FromRGBA(0.088f, 0.606f, 0.676f, 1.000f);
UIColor gradientColor2 = UIColor.FromRGBA(0.018f, 0.509f, 0.675f, 1.000f);
//// Gradient Declarations
var gradientColors = new CGColor [] {color.CGColor, UIColor.FromRGBA(0.066f, 0.607f, 0.837f, 1.000f).CGColor, gradientColor2.CGColor, gradientColor.CGColor};
var gradientLocations = new float [] {0, 0.21f, 0.46f, 1};
var gradient = new CGGradient(colorSpace, gradientColors, gradientLocations);
//// Rectangle Drawing
var rectanglePath = UIBezierPath.FromRect(new RectangleF(-46.5f, -35.5f, 728, 1192));
context.SaveState();
rectanglePath.AddClip();
context.DrawLinearGradient(gradient, new PointF(317.5f, -35.5f), new PointF(317.5f, 1156.5f), 0);
context.RestoreState();
UIColor.Black.SetStroke();
rectanglePath.LineWidth = 1;
rectanglePath.Stroke();
//END PAINTCODE
var converted = UIGraphics.GetImageFromCurrentImageContext ();
UIGraphics.EndImageContext ();
return converted;
}
开发者ID:Skalar,项目名称:Indexer,代码行数:35,代码来源:BlueSea.cs
示例4: MessageSummaryView
static MessageSummaryView ()
{
using (var colorspace = CGColorSpace.CreateDeviceRGB ())
{
gradient = new CGGradient (colorspace, new float [] { /* first */ .52f, .69f, .96f, 1, /* second */ .12f, .31f, .67f, 1 }, null); //new float [] { 0, 1 });
}
}
开发者ID:felixcollins,项目名称:MonoTouch.Dialog,代码行数:7,代码来源:MessageElement.cs
示例5: Draw
public override void Draw(CGRect rect)
{
using (CGContext context = UIGraphics.GetCurrentContext())
{
switch (_Style)
{
case SIAlertViewBackgroundStyle.Gradient:
{
nfloat[] locations = { 0.0f, 1.0f };
nfloat[] colors = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f };
CGGradient gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), colors, locations);
CGPoint center = new CGPoint(Bounds.Size.Width / 2, Bounds.Size.Height / 2);
nfloat radius = (nfloat)Math.Min(Bounds.Size.Width, Bounds.Size.Height);
context.DrawRadialGradient(gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation);
break;
}
case SIAlertViewBackgroundStyle.Solid:
{
UIColor.FromWhiteAlpha(0f, 0.5f).SetColor();
context.SetFillColor(UIColor.FromWhiteAlpha(0f, 0.5f).CGColor);
context.FillRect(Bounds);
break;
}
}
}
}
开发者ID:NinZine,项目名称:SIAlertView.Xamarin,代码行数:27,代码来源:SIAlertBackgroundWindow.cs
示例6: SetUp
private void SetUp()
{
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB ();
gradient = new CGGradient (
colorSpace,
new float[] { 0.95f, 0.95f, 0.95f, 1,
0.85f, 0.85f, 0.85f, 1},
new float[] { 0, 1 });
}
开发者ID:rajeshwarn,项目名称:GhostPractice-iPadRepo,代码行数:9,代码来源:TitleElement.cs
示例7: GradientTheme
public GradientTheme()
{
//BackgroundColor = UIColor.Clear;
TextColor = UIColor.Black;
TextShadowColor = UIColor.LightGray;
TextShadowOffset = new SizeF(1, 0);
gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new float[] { 0.95f, 0.95f, 0.95f, 1, 0.85f, 0.85f, 0.85f, 1 }, new float[] { 0, 1 });
}
开发者ID:RobertKozak,项目名称:MonoMobile.Views,代码行数:9,代码来源:GradientTheme.cs
示例8: 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
示例9: MovieElement
public MovieElement(string caption) : base(UITableViewCellStyle.Default)
{
Caption = caption;
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
gradient = new CGGradient(
colorSpace,
new float[] { 0.95f, 0.95f, 0.95f, 1,
0.85f, 0.85f, 0.85f, 1},
new float[] { 0, 1 } );
}
开发者ID:briandonahue,项目名称:MonoTouch.MVVM,代码行数:10,代码来源:MovieElement.cs
示例10: HeaderView
static HeaderView()
{
using (var rgb = CGColorSpace.CreateDeviceRGB()){
float [] colorsBottom = {
1, 1, 1, 1f,
0.97f, 0.97f, 0.97f, 1f
};
Gradient = new CGGradient (rgb, colorsBottom, null);
}
}
开发者ID:rcaratchuk,项目名称:CodeFramework,代码行数:10,代码来源:HeaderView.cs
示例11: 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
示例12: GradientTheme
public GradientTheme()
{
//BackgroundColor = UIColor.Clear;
TextColor = UIColor.Black;
TextShadowColor = UIColor.LightGray;
TextShadowOffset = new SizeF(1, 0);
gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new float[] { 0.95f, 0.95f, 0.95f, 1, 0.85f, 0.85f, 0.85f, 1 }, new float[] { 0, 1 });
DrawElementViewAction = (rect, context, cell) => { DrawElementView(rect, context, cell); };
}
开发者ID:vknair74,项目名称:MonoMobile.Views,代码行数:11,代码来源:GradientTheme.cs
示例13: GradientDrawingView
public GradientDrawingView () : base ()
{
using (var rgb = CGColorSpace.CreateDeviceRGB ()) {
nfloat[] colors = {
204f / 255f, 224f / 255f, 244f / 255f, 10f,
29f / 255f, 156f / 255f, 215f / 255f, 10f,
0f / 255f, 50f / 255f, 126f / 255f, 10f,
};
gradient = new CGGradient (rgb, colors, null);
}
}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:11,代码来源:RenderedDrawing.cs
示例14: DrawContentView
public void DrawContentView(RectangleF rect, CGContext context, UITableViewElementCell cell)
{
context.SaveState();
float r = 0;
float g = 0;
float b = 0;
var gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new float[] { r, g, b, 0.20f, r, g, b, 0.40f }, new float[] { 0, 1 });
context.DrawLinearGradient(gradient, new PointF(rect.Left, rect.Top), new PointF(rect.Left, rect.Bottom), CGGradientDrawingOptions.DrawsBeforeStartLocation);
context.RestoreState();
}
开发者ID:anujb,项目名称:MonoMobile.MVVM,代码行数:12,代码来源:SmokeyTheme.cs
示例15: SampleOwnerDrawnElement
public SampleOwnerDrawnElement (string text, DateTime sent, string from) : base(UITableViewCellStyle.Default, "sampleOwnerDrawnElement")
{
this.Subject = text;
this.From = from;
this.Sent = FormatDate(sent);
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
gradient = new CGGradient(
colorSpace,
new float[] { 0.95f, 0.95f, 0.95f, 1,
0.85f, 0.85f, 0.85f, 1},
new float[] { 0, 1 } );
}
开发者ID:hisystems,项目名称:MonoTouch.Dialog,代码行数:12,代码来源:DemoOwnerDrawnElement.cs
示例16: Draw
public override void Draw (RectangleF rect)
{
base.Draw (rect);
// get graphics context
CGContext gctx = UIGraphics.GetCurrentContext ();
// set up drawing attributes
gctx.SetLineWidth (4);
UIColor.Yellow.SetStroke ();
// stroke with a dashed line
gctx.SetLineDash (3, new float[] {6,2});
// create geometry
var path = new CGPath ();
PointF origin = new PointF (Bounds.GetMidX (),
Bounds.GetMinY () + 10);
path.AddLines (new PointF[] {
origin,
new PointF (origin.X + 35, origin.Y + 80),
new PointF (origin.X - 50, origin.Y + 30),
new PointF (origin.X + 50, origin.Y + 30),
new PointF (origin.X - 35, origin.Y + 80) });
path.CloseSubpath ();
// add geometry to graphics context and draw it
gctx.AddPath (path);
gctx.DrawPath (CGPathDrawingMode.Stroke);
// fill the star with a gradient
gctx.AddPath (path);
gctx.Clip ();
RectangleF starBoundingBox = path.BoundingBox;
float[] locations = { 0.0f, 1.0f };
float[] components = { 1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f };
using (var rgb = CGColorSpace.CreateDeviceRGB()) {
CGGradient gradient = new CGGradient (rgb, components, locations);
PointF gradientStart = new PointF (starBoundingBox.Left, starBoundingBox.Top);
PointF gradientEnd = new PointF (starBoundingBox.Right, starBoundingBox.Bottom);
gctx.DrawLinearGradient (gradient, gradientStart, gradientEnd, CGGradientDrawingOptions.DrawsBeforeStartLocation);
}
}
开发者ID:GSerjo,项目名称:Seminars,代码行数:52,代码来源:StarView.cs
示例17: Draw
public override void Draw (CGRect rect)
{
base.Draw (rect);
//get graphics context
using (CGContext g = UIGraphics.GetCurrentContext ()) {
//set up drawing attributes
g.SetLineWidth (10);
UIColor.Blue.SetFill ();
UIColor.Red.SetStroke ();
//create geometry
var path = new CGPath ();
path.AddLines (new CGPoint[]{
new CGPoint (100, 200),
new CGPoint (160, 100),
new CGPoint (220, 200)});
path.CloseSubpath ();
//use a dashed line
g.SetLineDash (0, new nfloat[]{10, 4});
//add geometry to graphics context and draw it
g.AddPath (path);
g.DrawPath (CGPathDrawingMode.FillStroke);
// add the path back to the graphics context so that it is the current path
g.AddPath (path);
// set the current path to be the clipping path
g.Clip ();
// the color space determines how Core Graphics interprets color information
using (CGColorSpace rgb = CGColorSpace.CreateDeviceRGB()) {
CGGradient gradient = new CGGradient (rgb, new CGColor[] {
UIColor.Blue.CGColor,
UIColor.Yellow.CGColor
});
// draw a linear gradient
g.DrawLinearGradient (
gradient,
new CGPoint (path.BoundingBox.Left, path.BoundingBox.Top),
new CGPoint (path.BoundingBox.Right, path.BoundingBox.Bottom),
CGGradientDrawingOptions.DrawsBeforeStartLocation);
}
}
}
开发者ID:g7steve,项目名称:monotouch-samples,代码行数:50,代码来源:TriangleView.cs
示例18: StoryDetailElement
public StoryDetailElement(AgileZenStory story)
: base(UITableViewCellStyle.Default, "sampleOwnerDrawnElement")
{
this.Text = story.Text;
this.Status = story.Status;
this.User = story.Owner.Name;
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
gradient = new CGGradient(
colorSpace,
new float[] { 0.95f, 0.95f, 0.95f, 1,
0.85f, 0.85f, 0.85f, 1},
new float[] { 0, 1 } );
}
开发者ID:GunioRobot,项目名称:AgileZen,代码行数:14,代码来源:StoryDetailElement.cs
示例19: TableViewSectionView
static TableViewSectionView ()
{
using (var rgb = CGColorSpace.CreateDeviceRGB()){
var colorsBottom = new nfloat[] {
1, 1, 1, 0f,
0.4f, 0.4f, 0.4f, .6f
};
BottomGradient = new CoreGraphics.CGGradient (rgb, colorsBottom, null);
var colorsTop = new nfloat[] {
0.8f, 0.8f, 0.8f, .4f,
1, 1, 1, 0f
};
TopGradient = new CoreGraphics.CGGradient (rgb, colorsTop, null);
}
}
开发者ID:runt18,项目名称:CodeHub,代码行数:15,代码来源:TableViewSectionView.cs
示例20: CellBackgroundView
static CellBackgroundView()
{
using (var rgb = CGColorSpace.CreateDeviceRGB()){
float [] colorsBottom = {
1, 1, 1, .5f,
0.91f, 0.91f, 0.91f, .5f
};
BottomGradient = new CGGradient (rgb, colorsBottom, null);
float [] colorsTop = {
0.94f, 0.94f, 0.94f, .5f,
1, 1, 1, 0.5f
};
TopGradient = new CGGradient (rgb, colorsTop, null);
}
}
开发者ID:sergii-tkachenko,项目名称:Gistacular,代码行数:15,代码来源:CellBackgroundView.cs
注:本文中的CGGradient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论