quartz-graphics

For iPad / iPhone apps, how to have an array of points?

僤鯓⒐⒋嵵緔 提交于 2019-12-23 12:46:08
问题 We can have an NSMutableArray object, and add objects to it. But CGPoint is not an object... are there Point objects suitable to be added to an NSMutableArray object? I see some code using NSStringFromCGPoint to create an NSString object so that it can be added to the array, and later use CGPointFromString to get the CGPoint back... but that just looks too much of a hack... 回答1: You can store the points in the array using NSValue as a wrapper: CGPoint a = CGPointMake(10.0, 10.0); [array

How to draw variable-width UIBezierPath?

跟風遠走 提交于 2019-12-23 12:14:03
问题 I'm wondering how I should go about drawing a uibezierpath where the stroke width peaks at the center of the arc. Here's an example of what I mean: Either I have to go through each point when drawing, and set the stroke width accordingly, or there's an easier way. Can anyone point me in the right direction? Thanks 回答1: You can just draw the two outer paths with no stroke, join them, and then fill in the space between them. 回答2: Another way to try this if you're interested: I ended up getting

I want to animate, in fact fade, “within” drawRect

北战南征 提交于 2019-12-23 07:57:19
问题 Is there a way to make drawRect animate FROM THE PREVIOUS SCENE to the next one? (Amazingly) you can animate inside drawRect - try it. You can fade, translate or animate any other property. However, it starts "from fresh", from blank. So for example if you put a fade-in animation block in drawRect, the previous scene with disappear and the new scene will fade up from white. I want the screen to fade from the previous image (drawn in the previous cycle of drawRect) to the new image I have just

CGPath with outline

断了今生、忘了曾经 提交于 2019-12-23 07:47:02
问题 I am trying to draw a CGPath that has a stroke for it's stroke. Basically I want a draw a line using CGPath. I then want to go back and draw lines on both sides of the last CGPath giving it the effect that it is outlines. This line can bend and turn in any way but I always need the two lines on the outside to follow. EDIT: I need to be able to make the middle of the line transparent but the outlines solid black. 回答1: Use CGPathCreateCopyByStrokingPath to create a new path by stroking your old

How to implement a Photoshop Curves editor in UIKit

旧城冷巷雨未停 提交于 2019-12-23 04:04:28
问题 I'm familiar with UIBezierPath and the corresponding CG routines, but none of them appear to draw the same type of path as what I see in Photoshop, etc. How would one go about this? I'm just talking about the UI--letting the user drag around points. A java example I found is here: http://www.cse.unsw.edu.au/~lambert/splines/natcubic.html 回答1: I would look into CGContextAddCurveToPoint and drag around curve's control points. If you require more control points to create a complex curve, just

Is it possible to to have more than one color in the same UILabel

梦想与她 提交于 2019-12-23 02:38:27
问题 I want more than one font color in the same UILabel. I dont know if it is possible. I dont really think so but maybe some of you out there have a smart solution for it? Maybe something like stringWithFormat . [NSString stringWithFormatAndColor: @"Text with color: %@ %@", text, color, text, color] This image illustrate what I'm trying to accomplish: 回答1: You can achieve this with NSAttributedSting. An easy to use drop-in replacement for UILabels with support for attributed strings is

mapping Futura font in quartz for use in ggplot

拟墨画扇 提交于 2019-12-23 02:27:29
问题 I would like Futura to be the default font for my ggplot graphs. I'm running MacOSX, writing out to pngs, so it appears the "extrafont" is not applicable. I've attempted mapping via quartzFont within the R environment with > quartzFonts(sans = quartzFont(rep("Futura", 4))) which appears to work because when I look at font mappings we have: > quartzFonts() $serif [1] "Times-Roman" "Times-Bold" "Times-Italic" "Times-BoldItalic" $sans [1] "Futura" "Futura" "Futura" "Futura" $mono [1] "Courier"

UIImagePNGRepresentation and masked images

旧城冷巷雨未停 提交于 2019-12-22 10:29:29
问题 I created a masked image using a function form an iphone blog: UIImage *imgToSave = [self maskImage:[UIImage imageNamed:@"pic.jpg"] withMask:[UIImage imageNamed:@"sd-face-mask.png"]]; Looks good in a UIImageView UIImageView *imgView = [[UIImageView alloc] initWithImage:imgToSave]; imgView.center = CGPointMake(160.0f, 140.0f); [self.view addSubview:imgView]; UIImagePNGRepresentation to save to disk : [UIImagePNGRepresentation(imgToSave) writeToFile:[self findUniqueSavePath] atomically:YES];

How to compare a shape drawn on the screen to a letter?

折月煮酒 提交于 2019-12-22 08:19:06
问题 I want to check the drawn shape matches a letter from the alphabet. It's a kids app for learning. When any one draw the shape then how can i detect it's a correct letter? 回答1: I don't have any sample code for you but this is how I'd do this, I think. You need to define or get a bezier path describing the shape of each letter - this would be an outline of a solid letter, not just a line drawing the letter shape. There may be a way to get this from the api, obtaining a bezier path from a glyph,

Scaling up iPhone “vector-based graphics” on affine transforms

女生的网名这么多〃 提交于 2019-12-22 07:00:13
问题 I made a "Circle" view with this drawRect - (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(ctx, color.CGColor); CGContextAddEllipseInRect(ctx, rect); CGContextFillPath(ctx); } When I try to scale the view up using CGAffineTransformMakeScale(2.0, 2.0) , the result is blurry and pixelated on the edges. However, the programming guide says that Quartz uses vector-based commands to draw views, and that they would continue to look good