core-graphics

Unexpected LineJoinStyle behavior when lines in path at 180 degrees

醉酒当歌 提交于 2019-12-21 14:11:15
问题 I'm getting a clipped LineJoin in a UIBezierPath when one line comes back exactly over the previous line. If I adjust the second line by one pixel, the LineJoin behaves as expected. Here's the code: UIBezierPath *path = [UIBezierPath bezierPath]; [path setLineWidth:10.0f]; [path setLineCapStyle:kCGLineCapRound]; [path setLineJoinStyle:kCGLineJoinRound]; [path moveToPoint:CGPointMake(100, 100)]; [path addLineToPoint:CGPointMake(200, 100)]; [path addLineToPoint:CGPointMake(150, 100)]; [path

Unexpected LineJoinStyle behavior when lines in path at 180 degrees

旧城冷巷雨未停 提交于 2019-12-21 14:10:11
问题 I'm getting a clipped LineJoin in a UIBezierPath when one line comes back exactly over the previous line. If I adjust the second line by one pixel, the LineJoin behaves as expected. Here's the code: UIBezierPath *path = [UIBezierPath bezierPath]; [path setLineWidth:10.0f]; [path setLineCapStyle:kCGLineCapRound]; [path setLineJoinStyle:kCGLineJoinRound]; [path moveToPoint:CGPointMake(100, 100)]; [path addLineToPoint:CGPointMake(200, 100)]; [path addLineToPoint:CGPointMake(150, 100)]; [path

Converting a NSString to a cString for use with CGContextShowTextAtPoint

≡放荡痞女 提交于 2019-12-21 12:42:17
问题 I am drawing a String using CGContextShowTextAtPoint. Thus I need to convert my NSString I want to draw into c Strings. Unfortunately special symbols like the euro currency symbol are not correctly shown. CGContextSelectFont(currentContext, "TrebuchetMS", 15, kCGEncodingMacRoman); CGContextShowTextAtPoint(currentContext, 0, 0, [myString cStringUsingEncoding:[NSString defaultCStringEncoding]], [myString length]); I tried it with the kCGEncodingFontSpecific encoding in the CGContextSelectFont

How to get the real RGBA or ARGB color values without premultiplied alpha?

早过忘川 提交于 2019-12-21 12:31:32
问题 I'm creating an bitmap context using CGBitmapContextCreate with the kCGImageAlphaPremultipliedFirst option. I made a 5 x 5 test image with some major colors (pure red, green, blue, white, black), some mixed colors (i.e. purple) combined with some alpha variations. Every time when the alpha component is not 255, the color value is wrong. I found that I could re-calculate the color when I do something like: almostCorrectRed = wrongRed * (255 / alphaValue); almostCorrectGreen = wrongGreen * (255

How to reset to identity the “current transformation matrix” with some CGContext function?

无人久伴 提交于 2019-12-21 11:14:13
问题 I'm doing a series of translations and rotations on the CTM and at some point I need to reset it to identity before going further with transformations. I can't find any proper way to do it (obviously, there should have been a function named CGContextSetCTM or so) and since efficiency is the key, I don't want to use CGContextSaveGState/CGContextRestoreGState... 回答1: Get current transformation matrix via CGContextGetCTM, invert it with CGAffineTransformInvert and multiply the current matrix by

How to reset to identity the “current transformation matrix” with some CGContext function?

天涯浪子 提交于 2019-12-21 11:13:30
问题 I'm doing a series of translations and rotations on the CTM and at some point I need to reset it to identity before going further with transformations. I can't find any proper way to do it (obviously, there should have been a function named CGContextSetCTM or so) and since efficiency is the key, I don't want to use CGContextSaveGState/CGContextRestoreGState... 回答1: Get current transformation matrix via CGContextGetCTM, invert it with CGAffineTransformInvert and multiply the current matrix by

Draw Rectangle On UIImage with Core Graphics

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-21 11:03:03
问题 I'm trying to put a rectangle at the center of a UIImage using Core Graphics to look roughly like this: This is my code so far: func drawRectangleOnImage(image: UIImage) -> UIImage { let imageSize = image.size let scale: CGFloat = 0 UIGraphicsBeginImageContextWithOptions(imageSize, false, scale) let context = UIGraphicsGetCurrentContext() let rectangle = CGRect(x: 0, y: (imageSize.height/2) - 30, width: imageSize.width, height: 60) CGContextSetFillColorWithColor(context, UIColor.blackColor()

UIView shadow and InterfaceBuilder

时光怂恿深爱的人放手 提交于 2019-12-21 07:28:36
问题 I want to add a drop shadow using CALayer to a UI(Image)View. The following code works generally fine previewImage.layer.shadowColor = [[UIColor blackColor] CGColor]; previewImage.layer.shadowOffset = CGSizeMake(1.0f, 1.0f); previewImage.layer.shadowOpacity = 1.0f; previewImage.layer.shadowRadius = 8.0f; However, this only works if I create that view programmatically and add it as a subview to my main view. When that view is set up in InterfaceBuilder and defined as an IBOutlet UIImageView

How can I save a Bitmap Image, represented by a CGContextRef, to the iPhone's hard drive?

ぃ、小莉子 提交于 2019-12-21 06:27:00
问题 I have a little sketch program that I've managed to throw together using Quartz2D, but I'm very new to the iOS platform and I'm having trouble figuring out how to allow the user to save their sketch. I have a CGContextRef that contains the sketch, how can I save it so that it can later be retrieved? Once it's saved, how can I retrieve it? Thanks so much in advance for your help! I'm going to continue reading up on this now... 回答1: There are different types of CGContexts. You are most likely

Drawing around CGContextRef to remove pixelation

佐手、 提交于 2019-12-21 05:54:29
问题 Currently, I am having a graphical issue with drawing small dots. I notice that in most professional Calendar applications, the events calendar indentifier is a small dot whose color is the events calendar color. I am current at the point of my application where I need to draw a BETTER dot. Heres a photo of what I mean. It may not be noticeable here but the colored dot is pretty pixelated when its on my phone. I would like to remove the pixelation. I went through a tutorial from Ray