core-graphics

Drawing half-circles with CoreGraphics

风流意气都作罢 提交于 2019-12-13 15:30:40
问题 I know how to draw lines and shapes with CGPath s . But I couldn't figure out how to draw this symbol for a circuit diagram What code should I write to get that half circle shape? This is what I have so far: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 5.0); CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); CGContextMoveToPoint(context, 60, 80); CGContextAddLineToPoint(context, 120, 80);

How to make a button or label above a CALayer in Xcode?

谁说胖子不能爱 提交于 2019-12-13 15:13:42
问题 In my storyboard I added a button & a label. In my ViewController I programmatically defined a CALayer and added it as a sublayer to the ViewController's view. When I test the app the sublayer is above the button and the label but I want to make the sublayer below the button and the label. here's the code .h file // The CALayer declaration CALayer *graphic; .m file //The screen width and height CGRect screenBound = [[UIScreen mainScreen] bounds]; CGSize screenSize = screenBound.size; CGFloat

Getting pixel data on iOS 8 / iPhone 6

大城市里の小女人 提交于 2019-12-13 14:13:29
问题 I need to retrieve the pixel data for a given (x, y) coordinate of a bitmap image. For years my code has been as follows: _palettePixelData = CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage)); const UInt8 *rawData = CFDataGetBytePtr(_imagePixelData); int pixelInfo = ((image.size.width * floorf(pointInImage.y) * image.scale) + floorf(pointInImage.x) * image.scale ) * 4; CGFloat red = rawData[pixelInfo + 0] / 255.0; CGFloat green = rawData[pixelInfo + 1] / 255.0; CGFloat blue =

CGContextStrokeRect is drawing only a side of rect

荒凉一梦 提交于 2019-12-13 14:06:27
问题 I need to draw a rect filled with color and its border... the rect is filled with color properly but the outside border is partially drawn, just the right side of the rect is drawn! The generated UIImage is going to be used in a UITableViewCell's imageView. - (UIImage *)legendItemWithColor:(UIColor *)color { UIGraphicsBeginImageContext(self.view.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGRect outside = CGRectMake(128, 128, 128, 128); CGRect legend = CGRectInset

Is there an alternative to CGPath which allows to compute points on a path for a given location?

时间秒杀一切 提交于 2019-12-13 12:09:22
问题 For an animation timing algorithm I need to supply a path as the curve. Probably a bezier curve with control points on both ends. The problem is that it seems not possible to calculate points on a CGPath because CGPathRef is opaque. Also Apple provides no mechanism to compute points on a path. Is there a library or utility class which can compute points on a bezier curve or path, for a given location like 0.5 for the middle along the path? Or let me rephrase it: If CGPath / CGPathRef makes

Any possible way for CoreGraphics to not lag when drawrect is being called from touches moved?

人盡茶涼 提交于 2019-12-13 07:06:37
问题 I am calling setNeedsDisplay from touches moved (and have also tried not calling from touches moved, but instead from a 0.05 timer) and the drawrect method is always laggy. Is their anyway to change this? I am doing a lot of drawing in drawrect but I have no idea for a solution to fix the lag. Even when the timer was called at a 1.0 interval than it still lagged when the timer called the selector. Also, I have no leaks (I checked using Xcode analyze feature ). Please help!! EDIT: I am calling

Custom Shaped progress View

最后都变了- 提交于 2019-12-13 07:04:31
问题 I'm looking out for some solution regarding the custom progress view. Basically, i would like to fill the image below to represent the loading progress,just like the one's we have in games. Any ideas how to achieve it?? 回答1: Masking using CoreGraphics: UIImage *img = [UIImage imageNamed:@"imagetomask.png"]; CGImageRef maskRef = [UIImage imageNamed:@"mask.png"].CGImage; CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef),

GLKit masking or blending 2 textures both from jpegs no alphas

三世轮回 提交于 2019-12-13 06:06:22
问题 I am using GLKit, and at 24 fps I need to take a CGImageRef (no alpha layer) and apply another CGImageRef (no alpha layer) as a mask to it (black and white image) and render the result as a GLKit texture. At first I tried this approach: CGImageRef actualMask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef), CGImageGetBitsPerPixel(maskRef), CGImageGetBytesPerRow(maskRef), CGImageGetDataProvider(maskRef), NULL, false); CGImageRef

NSSavePanel, CGImageDestinationFinalize and OS X sandbox

霸气de小男生 提交于 2019-12-13 05:25:38
问题 I'm using NSSavePanel to let user select image to save to in my app. Everything worked fine until I enabled app sandboxing and entitlements. The problem occurs with selection of an already existing file. My code is like this: // Create a URL to our file destination and a CGImageDestination to save to. CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL((CFURLRef)[savePanel URL], (CFStringRef)newUTType, 1, NULL); CGImageDestinationAddImage(imageDestination, cgimage,

Memory Leak in Objective C function with ARC

耗尽温柔 提交于 2019-12-13 05:17:21
问题 here is the function from the library MGSpotyViewController, but I am asking what to watch out in this kind of situations. I am used to C++ and maintaining my own objects but I can't find the problem here. I tried very basic pieces of codes with UIGraphicsBeginImageContextWithOptions and memory still increased slightly but I wasn't sure if I located the problem or that's because the GC hasn't run yet. To test the following function I did: - (BOOL)application:(UIApplication *)application