core-graphics

CGColorRef causing crash

落花浮王杯 提交于 2019-12-03 04:43:07
I've had a crash in my code, and I've tracked it all the way back to a line crashing when being passed 2 CGColorRefs. Here are the objects: CGColorRef startColor = [[UIColor colorWithWhite:0.92 alpha:1.0]CGColor]; CGColorRef endColor = [[UIColor colorWithWhite:0.94 alpha:1.0]CGColor]; NSLog(@"start: %@ end: %@", startColor, endColor); The NSLog returns a crash. What's wrong with them? EDIT - where it's crashing: CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGFloat locations[] = { 0.0, 1.0 }; NSArray *colors = [NSArray arrayWithObjects:(__bridge_transfer id)startColor, (__bridge

Stroking paths using a pattern color to simulate brush texture

谁说我不能喝 提交于 2019-12-03 04:40:57
问题 I am making a finger painting app and I am having a hard time giving my brush a nice brush-like feel and texture. I have this code: UIColor * brushTexture = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Brush_Black.png"]]; CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), brushTexture.CGColor); but my output is like this: The texture of my brush is tiled. How can I make it fit to the stroke Size and stop the tiling of the image? 回答1: Here i found a solution! UIImage

Erase and un erase a image in UIImageVIew with touch using coregraphics

自古美人都是妖i 提交于 2019-12-03 04:28:24
My question is same as mentioned at here . I'm also using two images in my app and all I need is to erase a top image by touch. Then un-erase (if required) the erased part by touch. I'm using following code to erase the the top image. There is also a problem in this approach. Which is that the images are big and I'm using Aspect Fit content mode to properly display them. When I touch on the screen, it erase in the corner not the touched place. I think the touch point calculation is required some fix. Any help will be appreciated. Second problem is that how to un-erase the erased part by touch?

What is the most memory-efficient way of downscaling images on iOS?

旧巷老猫 提交于 2019-12-03 04:16:33
问题 In background thread, my application needs to read images from disk, downscale them to the size of screen (1024x768 or 2048x1536) and save them back to disk. Original images are mostly from the Camera Roll but some of them may have larger sizes (e.g. 3000x3000). Later, in a different thread, these images will frequently get downscaled to different sizes around 500x500 and saved to the disk again. This leads me to wonder: what is the most efficient way to do this in iOS, performance and memory

Loading UIImage in background thread causes ImageIO error

谁都会走 提交于 2019-12-03 04:05:42
I am working on an iOS project that loads UIImages from URLs in a background thread and displays them in a horizontally paged scroll view. This behavior should mimic that of the native photo library application for iPhone. I have everything setup in a way that I believe should work, but upon drawing the UIImages in the main UI graphics context, I occasionally see this message print out in the console: ImageIO: <ERROR> CGImageReadSessionGetCachedImageBlockData *** CGImageReadSessionGetCachedImageBlockData: bad readSession [0x685e590] Despite this error, it appears that the app functions

How to draw a concentric circle in iphone?

浪尽此生 提交于 2019-12-03 04:04:09
I want to draw a ring. Ring should filled in a outer circle. I referred a documentation http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_paths/dq_paths.html#//apple_ref/doc/uid/TP30001066-CH211-TPXREF101 . But still had problem to get the outcome. Here is the code. CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextClearRect(ctx, rect); CGContextSetRGBFillColor(ctx, 0.0, 255.0, 1.0, 1.0);CGContextFillPath(ctx); CGContextStrokeEllipseInRect(ctx, CGRectMake(125, 125, 150, 150)); CGContextBeginPath(ctx); CGContextEOFillPath(ctx);

Why is -drawRect faster than using CALayers/UIViews for UITableViews?

烈酒焚心 提交于 2019-12-03 03:52:14
I can already hear the wrenching guts of a thousand iOS developers. No, I am not noob. Why is -drawRect faster for UITableView performance than having multiple views? I understand that compositing operations take place on the GPU. But compositing is a one-time operation; once the layers are committed to memory, it is no different from a cached buffer that, from the point of view of the GPU, gets translated in and out of view. Compare this to using Core Graphics in drawRect, which employ an unknown amount of operations on the CPU to produce pixels that end up getting cached in CALayers anyway.

How to highlight CoreText with changing highlight colors?

末鹿安然 提交于 2019-12-03 03:42:26
I have a subclass of UIView that implements code to draw CoreText. In the application, that UIView is drawn inside a UIScrollView. Here is the code that I currently use in drawRect: to render an NSAttributedString: CGContextRef context = UIGraphicsGetCurrentContext(); float viewHeight = self.bounds.size.height; CGContextTranslateCTM(context, 0, viewHeight); CGContextScaleCTM(context, 1.0, -1.0); CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, 1.0)); CGMutablePathRef path = CGPathCreateMutable(); CGRect bounds = CGRectMake(PADDING_LEFT, -PADDING_TOP, self.bounds.size.width-20.0,

Xcode: compositing with alpha using core image

左心房为你撑大大i 提交于 2019-12-03 03:35:30
I'd like to create a CoreImage filter chain, and to be able to control the "intensity" of each filter in the chain by compositing its individual effect with alpha, or opacity settings, but I am not seeing a way to composite with alpha or opacity in the docs. I could jump out of Core image filter chain and composite with a core graphics context I guess. The CIColorMatrix filter can be used to alter the alpha component of a CIImage, which you can then composite onto a background image: CIImage *overlayImage = … // from file, CGImage etc CIImage *backgroundImage = … // likewise CGFloat alpha = 0

CGContext rotation

♀尐吖头ヾ 提交于 2019-12-03 03:27:58
I have a 100x100 pixel image that I want to draw at various angles rotated around the center of the image. The following code works, but rotates around the original origo of the coordinate system (upper left hand corner) and not the translated location. Thus the image is not rotated around itself but around the upper left corner of the screen. The following code was run in a custom view in a blank application with nothing else but this. - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextTranslateCTM(context, -50, -50); CGContextRotateCTM (context, 0