cgcontext

iOS draw filled Circles

六眼飞鱼酱① 提交于 2019-11-27 09:51:51
问题 Not a graphics programmer here, so I'm trying to stumble through this. I'm trying to draw 9 filled circles, each a different color, each with a white border. The UIView's frame is CGRectMake (0,0,60,60). See attached image. The problem is I'm getting "flat spots" on the borders on each side. Following is my code (from the UIView subclass): - (void)drawRect:(CGRect)rect { CGRect borderRect = CGRectMake(0.0, 0.0, 60.0, 60.0); CGContextRef context = UIGraphicsGetCurrentContext();

Track touch points in Multitouch

不羁岁月 提交于 2019-11-27 07:49:15
问题 I am working on a drawing project, I want to support multitouch, I have gone through documentation online, which suggest to track the touch points, I did it , But I am not getting the desired behaviour. I am not getting straight lines. Below is my code - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. red = 0.0/255.0; green = 0.0/255.0; blue = 0.0/255.0; brush = 10.0; opacity = 1.0; self.view.multipleTouchEnabled = YES;

Calculate controlPoints while drawing in iOS

六月ゝ 毕业季﹏ 提交于 2019-11-27 07:11:13
问题 I am working on a drawing app, where user can draw/write with his finger or stylus. For this I have referred code from https://github.com/yusenhan/Smooth-Line-View , in my application. The problem which I am facing is that, the writing sometimes when you write very closely is not very smooth. So I think, I am making some mistake in getting the control point. Below is my code //Find the midpoint CGPoint midPoint(CGPoint p1, CGPoint p2) { return CGPointMake((p1.x + p2.x) * 0.5, (p1.y + p2.y) *

Changing UIImage color

怎甘沉沦 提交于 2019-11-27 06:07:24
I'm trying to change color of UIImage. My code: -(UIImage *)coloredImage:(UIImage *)firstImage withColor:(UIColor *)color { UIGraphicsBeginImageContext(firstImage.size); CGContextRef context = UIGraphicsGetCurrentContext(); [color setFill]; CGContextTranslateCTM(context, 0, firstImage.size.height); CGContextScaleCTM(context, 1.0, -1.0); CGContextSetBlendMode(context, kCGBlendModeCopy); CGRect rect = CGRectMake(0, 0, firstImage.size.width, firstImage.size.height); CGContextDrawImage(context, rect, firstImage.CGImage); CGContextClipToMask(context, rect, firstImage.CGImage); CGContextAddRect

Setting A CGContext Transparent Background

邮差的信 提交于 2019-11-27 05:35:09
问题 I am still struggling with drawing a line with CGContext. I have actually go to line to draw, but now I need the background of the Rect to be transparent so the existing background shows thru. Here's my test code: (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); CGContextSetAlpha(context,0.0); CGContextFillRect(context, rect); CGContextSetStrokeColorWithColor(context, [UIColor whiteColor]

Drawing a polygon with one color for stroke, and a different one for fill?

自闭症网瘾萝莉.ら 提交于 2019-11-27 02:23:49
问题 I'm having trouble with drawing some lines that are stroked with a color and then filling their insides (they make a polygon) with another one. UIColor *houseBorderColor = [UIColor colorWithRed:(170/255.0) green:(138/255.0) blue:(99/255.0) alpha:1]; CGContextSetStrokeColorWithColor(context, houseBorderColor.CGColor); CGContextSetLineWidth(context, 3); // Draw the polygon CGContextMoveToPoint(context, 20, viewHeight-19.5); CGContextAddLineToPoint(context, 200, viewHeight-19.5); // base

CGBitmapContextCreate error with swift

江枫思渺然 提交于 2019-11-27 02:04:30
问题 I am trying to create a CGContext in swift. It compiles but throws an error at runtime. let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB() let context:CGContext = CGBitmapContextCreate(nil, 20, 20, 8, 0, colorSpace, CGBitmapInfo.AlphaInfoMask) CGColorSpaceRelease(colorSpace); .... And the error is: Error: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; unrecognized; 96 bytes/row. fatal error: Can't unwrap

Convert Image to B&W problem CGContext - iPhone Dev

半城伤御伤魂 提交于 2019-11-27 01:42:58
问题 I am using a method to convert images taken with the camera into black and white. The problem I'm running into is that if the picture is taken in Portrait mode, it rotates and stretches in the next view. But, if is taken in landscape it is just find. I can only duplicate this bug when I convert the image to Black And White. Here is the method I am using. Im not 100% that this bug is from the conversion, but it only happens when its converted. Oh ya. This is the iOS 4. /// - (UIImage *

Create new UIImage by adding shadow to existing UIImage

♀尐吖头ヾ 提交于 2019-11-27 01:41:02
问题 I've taken a look at this question: UIImage Shadow Trouble But the accepted answer didn't work for me. What I'm trying to do is take a UIImage and add a shadow to it, then return a whole new UIImage, shadow and all. This is what I'm trying: - (UIImage*)imageWithShadow { CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef shadowContext = CGBitmapContextCreate(NULL, self.size.width, self.size.height + 1, CGImageGetBitsPerComponent(self.CGImage), 0, colourSpace,

drawRect drawing 'transparent' text?

你说的曾经没有我的故事 提交于 2019-11-27 00:39:39
问题 I am looking to draw a UILabel (preferable through subclassing) as a transparent label, but with solid background. I draw up an quick example (sorry, it's ugly, but it gets the points across :)). Basically I have a UILabel and I would like the background to be a set colour, and the text should be transparent. I do not want to colour the text with the views background, but instead have it be 100% transparent, since I have a texture in the background that I want to make sure lines up inside and