macOS Use CGContextRef and always black
up vote
0
down vote
favorite
I try to use this solution to build a gradient circle by @Johnny Rockex on macOS.But I got some problems.
In the @Johnny Rockex original answer
//3.1 setup
UIBezierPath * bezierPath;
CGPoint center = CGPointMake(dimension/2, dimension/2);
UIGraphicsBeginImageContextWithOptions(CGSizeMake(dimension, dimension), true, 0.0);
UIRectFill(CGRectMake(0, 0, dimension, dimension));
this method is provided by UIKit rather than AppKit. So I use some methods by AppKit
NSImage *contentView =[[NSImage alloc]initWithSize:NSMakeSize(dimension, dimension)];
[contentView lockFocus];
[NSGraphicsContext currentContext].imageInterpolation = NSImageInterpolationNone;
CGContextRef gc = [[NSGraphicsContext currentContext]CGContext];
NSRectFill(CGRectMake(0, 0, dimension, dimension));
//fill Colors in bazierPath
for (int n = 0; n<numberOfColors;n++) {
...
}
[contentView unlockFocus];
[radialGradient setImage:contentView];
Unfortunately, I got a weird result at last
My colors array and bazierPath is correct but only a little part of the image has color.
Maybe is not caused by the title despection but I can not find any clue in other parts of codes.
macos core-graphics nsbezierpath
add a comment |
up vote
0
down vote
favorite
I try to use this solution to build a gradient circle by @Johnny Rockex on macOS.But I got some problems.
In the @Johnny Rockex original answer
//3.1 setup
UIBezierPath * bezierPath;
CGPoint center = CGPointMake(dimension/2, dimension/2);
UIGraphicsBeginImageContextWithOptions(CGSizeMake(dimension, dimension), true, 0.0);
UIRectFill(CGRectMake(0, 0, dimension, dimension));
this method is provided by UIKit rather than AppKit. So I use some methods by AppKit
NSImage *contentView =[[NSImage alloc]initWithSize:NSMakeSize(dimension, dimension)];
[contentView lockFocus];
[NSGraphicsContext currentContext].imageInterpolation = NSImageInterpolationNone;
CGContextRef gc = [[NSGraphicsContext currentContext]CGContext];
NSRectFill(CGRectMake(0, 0, dimension, dimension));
//fill Colors in bazierPath
for (int n = 0; n<numberOfColors;n++) {
...
}
[contentView unlockFocus];
[radialGradient setImage:contentView];
Unfortunately, I got a weird result at last
My colors array and bazierPath is correct but only a little part of the image has color.
Maybe is not caused by the title despection but I can not find any clue in other parts of codes.
macos core-graphics nsbezierpath
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I try to use this solution to build a gradient circle by @Johnny Rockex on macOS.But I got some problems.
In the @Johnny Rockex original answer
//3.1 setup
UIBezierPath * bezierPath;
CGPoint center = CGPointMake(dimension/2, dimension/2);
UIGraphicsBeginImageContextWithOptions(CGSizeMake(dimension, dimension), true, 0.0);
UIRectFill(CGRectMake(0, 0, dimension, dimension));
this method is provided by UIKit rather than AppKit. So I use some methods by AppKit
NSImage *contentView =[[NSImage alloc]initWithSize:NSMakeSize(dimension, dimension)];
[contentView lockFocus];
[NSGraphicsContext currentContext].imageInterpolation = NSImageInterpolationNone;
CGContextRef gc = [[NSGraphicsContext currentContext]CGContext];
NSRectFill(CGRectMake(0, 0, dimension, dimension));
//fill Colors in bazierPath
for (int n = 0; n<numberOfColors;n++) {
...
}
[contentView unlockFocus];
[radialGradient setImage:contentView];
Unfortunately, I got a weird result at last
My colors array and bazierPath is correct but only a little part of the image has color.
Maybe is not caused by the title despection but I can not find any clue in other parts of codes.
macos core-graphics nsbezierpath
I try to use this solution to build a gradient circle by @Johnny Rockex on macOS.But I got some problems.
In the @Johnny Rockex original answer
//3.1 setup
UIBezierPath * bezierPath;
CGPoint center = CGPointMake(dimension/2, dimension/2);
UIGraphicsBeginImageContextWithOptions(CGSizeMake(dimension, dimension), true, 0.0);
UIRectFill(CGRectMake(0, 0, dimension, dimension));
this method is provided by UIKit rather than AppKit. So I use some methods by AppKit
NSImage *contentView =[[NSImage alloc]initWithSize:NSMakeSize(dimension, dimension)];
[contentView lockFocus];
[NSGraphicsContext currentContext].imageInterpolation = NSImageInterpolationNone;
CGContextRef gc = [[NSGraphicsContext currentContext]CGContext];
NSRectFill(CGRectMake(0, 0, dimension, dimension));
//fill Colors in bazierPath
for (int n = 0; n<numberOfColors;n++) {
...
}
[contentView unlockFocus];
[radialGradient setImage:contentView];
Unfortunately, I got a weird result at last
My colors array and bazierPath is correct but only a little part of the image has color.
Maybe is not caused by the title despection but I can not find any clue in other parts of codes.
macos core-graphics nsbezierpath
macos core-graphics nsbezierpath
edited Nov 8 at 8:32
asked Nov 8 at 8:16


Shucheng
45110
45110
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Unlike UIBezierPath, appendBezierPathWithArcWithCenter is measured in degrees.
New contributor
Newbie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Yes, I found it and fixed this problem. Thanks
– Shucheng
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Unlike UIBezierPath, appendBezierPathWithArcWithCenter is measured in degrees.
New contributor
Newbie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Yes, I found it and fixed this problem. Thanks
– Shucheng
2 days ago
add a comment |
up vote
0
down vote
accepted
Unlike UIBezierPath, appendBezierPathWithArcWithCenter is measured in degrees.
New contributor
Newbie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Yes, I found it and fixed this problem. Thanks
– Shucheng
2 days ago
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Unlike UIBezierPath, appendBezierPathWithArcWithCenter is measured in degrees.
New contributor
Newbie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Unlike UIBezierPath, appendBezierPathWithArcWithCenter is measured in degrees.
New contributor
Newbie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Newbie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 2 days ago
Newbie
16
16
New contributor
Newbie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Newbie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Newbie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Yes, I found it and fixed this problem. Thanks
– Shucheng
2 days ago
add a comment |
Yes, I found it and fixed this problem. Thanks
– Shucheng
2 days ago
Yes, I found it and fixed this problem. Thanks
– Shucheng
2 days ago
Yes, I found it and fixed this problem. Thanks
– Shucheng
2 days ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203731%2fmacos-use-cgcontextref-and-always-black%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password