core-graphics

How to render stretched text in iOS?

风流意气都作罢 提交于 2019-12-18 10:31:31
问题 Given a rectangular area, I want to render some text using a specific font and have the rendered text fill out the rectangle . As in the image below: This is not the same as just changing font size Rendering it as a bitmap and then scale it is not an option (it looks horrible) Vector graphics is the way to do it Solution I came up with the following which seems to work for my purposes. The code draws a single line of text scaling to fill the bounds. Subclass UIView and replace drawRect as

UIView transparent gradient

强颜欢笑 提交于 2019-12-18 10:05:43
问题 Given an arbitrary UIView on iOS, is there a way using Core Graphics (CAGradientLayer comes to mind) to apply a "foreground-transparent" gradient to it? I can't use a standard CAGradientLayer because the background is more complex than a UIColor. I also can't overlay a PNG because the background will change as my subview is scrolled along its parent vertical scrollview (see image). I have a non-elegant fallback: have my uiview clip its subviews and move a pre-rendered gradient png of the

How can I set the mouse position?

北城余情 提交于 2019-12-18 07:11:50
问题 I need to set the position of the mouse on the screen. In some other similar question, it was suggested to use CGDisplayMoveCursorToPoint(CGDirectDisplayID display, CGPoint point) , but I cannot figure out how to get the CGDirectDisplayID . Please tell me how to get the CGDirectDisplayID or a different method to set the mouse position. 回答1: The real answer to this question is: CGMainDisplayID() https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/Quartz_Services_Ref

How can I get the contents of an std::string into a CFData object?

孤者浪人 提交于 2019-12-18 07:07:29
问题 I've got a function that returns a std::string object. I'm working with Cocoa/CoreGraphics and I need a way to get the data from that string into a CFData object so that I can feed that into a CGDataProviderCreateWithCFData object to make a CGImage . The CreateCFData function wants a const UInt8* object ( UInt8 being a typedef for unsigned char ). The string represents the bytes from a decoded Base64 string (image data), so it appears to contain many null "characters" so the obvious casting

Is it possible to make a NSBitmapImageRep with 24 bpp and no alpha channel?

浪子不回头ぞ 提交于 2019-12-18 07:02:46
问题 I don't understand really well the premultiplied alpha. I need a NSBitmapImageRep without alpha channel (I don't need a particular bpp). My problem is that this code give me errors: NSSize imageSize = NSMakeSize(200, 200); //create a non-alpha RGB image rep with the same dimensions as the image NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:imageSize.width pixelsHigh:imageSize.height bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO

iOS: CGImageCreateWith[PNG or JPEG]DataProvider causes segmentation fault

无人久伴 提交于 2019-12-18 05:54:20
问题 I'm facing a weird problem. I'm developing an iOS command line barcode scanner utility using libzbar (yes, this is for jailbroken devices). All goes fine except when I'm trying to use the CGImageCreateWithPNGDataProvider() or CGImageCreateWithJPEGDataProvider() methods to obtain a CGImageRef from a file - because these two functions throw a segfault on my 5.1.1 iPad. The problem is not in my custom class, ZBarScanner , because if I use an UIImage to obtain the image data, using something like

iOS: CGImageCreateWith[PNG or JPEG]DataProvider causes segmentation fault

落花浮王杯 提交于 2019-12-18 05:53:22
问题 I'm facing a weird problem. I'm developing an iOS command line barcode scanner utility using libzbar (yes, this is for jailbroken devices). All goes fine except when I'm trying to use the CGImageCreateWithPNGDataProvider() or CGImageCreateWithJPEGDataProvider() methods to obtain a CGImageRef from a file - because these two functions throw a segfault on my 5.1.1 iPad. The problem is not in my custom class, ZBarScanner , because if I use an UIImage to obtain the image data, using something like

Using CALayer's renderInContext: method with geometryFlipped

烂漫一生 提交于 2019-12-18 04:50:35
问题 I have a CALayer ( containerLayer ) that I'm looking to convert to a NSBitmapImageRep before saving the data out as a flat file. containerLayer has its geometryFlipped property set to YES, and this seems to be causing issues. The PNG file that is ultimately generated renders the content correctly, but doesn't seem to takes the flipped geometry into account. I'm obviously looking for test.png to accurately represent the content shown to the left. Attached below is a screenshot of the problem

when should you use __bridge vs. CFBridgingRelease/CFBridgingRetain?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 03:56:08
问题 I have this code that uses "__bridge" to cast the ids of colors: CGColorRef tabColor = (5 == 5 ? [UIColor blueColor].CGColor : [UIColor greenColor].CGColor); CGColorRef startColor = [UIColor whiteColor].CGColor; CGColorRef endColor = tabColor; NSArray *colors = [NSArray arrayWithObjects:(__bridge id)startColor, (__bridge id)endColor, nil]; CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations); but would: NSArray *colors = [NSArray

CGGradient in an CGPath

偶尔善良 提交于 2019-12-18 03:44:55
问题 Is it possible to draw a gradient in a path on the iPhone? I'm looking for a replacement of the mac os x method -(void)drawInBezierPath:(NSBezierPath *)path relativeCenterPosition:(NSPoint)relativeCenterPosition of NSGradient. 回答1: I think something like this will work: CGContextSaveGState(c); CGContextAddPath(c, path); CGContextClip(c) // make a gradient CGColorRef colors[] = { topColor, bottomColor }; CFArrayRef colorsArr = CFArrayCreate(NULL, (const void**)colors, sizeof(colors) / sizeof