quartz-2d

What this error is invalid context 0x0?

浪尽此生 提交于 2019-12-04 09:29:29
I wrote the following code in ViewDidLoad // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. -(void)viewDidLoad { [super viewDidLoad]; NSString *str = [NSString stringWithFormat:@"Veer"]; CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB(); CGFloat values[4] = {55.0, 0.0, 0.0, 1.0}; CGColorRef glowColor = CGColorCreate(rgbColorspace, values); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetShadowWithColor( context, CGSizeMake( 5.0, 0.0 ), 20.0f, glowColor); [str drawAtPoint:CGPointMake(10.5f, 0.5f) withFont:[UIFont

How do I change a partially transparent image's color in iOS?

一世执手 提交于 2019-12-04 08:05:29
问题 I have a single-color image that has partial transparency. I have both normal and @2X versions of the image. I would like to be able to tint the image a different color, in code. The code below works fine for the normal image, but the @2X ends up with artifacts. The normal image might have a similar issue If so, I can't detect it on account of resolution. +(UIImage *) newImageFromMaskImage:(UIImage *)mask inColor:(UIColor *) color { CGImageRef maskImage = mask.CGImage; CGFloat width = mask

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

混江龙づ霸主 提交于 2019-12-04 06:31:43
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 / alphaValue); almostCorrectBlue = wrongBlue * (255 / alphaValue); But the problem is, that my

Quartz 2d / Core Graphics: What is the right way to draw some text?

女生的网名这么多〃 提交于 2019-12-04 05:22:35
I've been at this for awhile, it seems that there's many ways to go about this in quartz 2d: 1) Draw text using core graphics methods... CGContextSelectFont CGContextSetRGBFillColor CGContextShowTextAtPoint and on and on, which is horribly low level. 2) using NSString drawAtPoint (so far the method I like) NSString* text = @"Hello"; [text drawAtPoint:point withFont:font]; 3) using UILabel I've read this somewhere but not too sure if this is possible. but I'm thinking that instantiating a UILabel within drawRect would be pretty costly as drawRect probably gets called a zillion times. ?? I'm

Custom “resizable image” drawing in iOS

佐手、 提交于 2019-12-04 03:39:32
问题 The UIImage API provides methods to resize an image in a way that certain areas get stretched, while others remain unaltered - great for background images for resizable UI elements. Now I am looking for a way to customize this behavior for more complex background images. This is what - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets; does. The transparent areas remain unaltered, the red areas are stretched when the view size is changed. This is what i want - finer grained

Clipping a CGGradient to a CGPath

和自甴很熟 提交于 2019-12-03 21:25:54
I've been banging my head against the wall for a long while trying to figure out why this is not working. Basically, I am trying to plot a graph (chart) with CGPath and then use that to clip a gradient. The end effect should be like the Stocks app which comes with the iPhone. The gradient and the path draw fine separately as two layered (unclipped) elements. But if I comment out the CGContextDrawPath, neither the line nor the gradient draw to the screen. Here's my drawRect code: CGContextRef context = UIGraphicsGetCurrentContext(); [[UIColor whiteColor] set]; CGContextSetLineWidth(context, 2

Saving a PDF document to disk using Quartz

会有一股神秘感。 提交于 2019-12-03 21:24:30
I am trying to draw a pdf page onto a pdf context and then save it to disk. I cannot seem to figure out what is wrong. Can someone give me a few pointers. Thanks. - (void)testQuartz:(NSData *)pdfDocumentData { //Create the pdf document reference CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((CFDataRef)pdfDocumentData); CGPDFDocumentRef document = CGPDFDocumentCreateWithProvider(dataProvider); CGDataProviderRelease(dataProvider); //Release the data provider //Create the pdf context CGPDFPageRef page = CGPDFDocumentGetPage(document, 0); CGRect pageRect = CGPDFPageGetBoxRect

Writing with digital pen on ipad/iphone by keeping hand on screen

∥☆過路亽.° 提交于 2019-12-03 21:10:19
I am working on a drawing app, with pen touch, on iphone and ipad. Till now , I have implemented the basic drawing and tested with digital pen and it work fine, but I have one issue, while drawing on iphone/ipad, if my fingers touch the screen before I draw with pen , the pen wont work, So what I want to achieve is that, I want to able to write with pen, even if my fingers are touching the ipad screen. Regards Ranjit There is no way to differentiate between a finger and a stylus, as a stylus is supposed to emulate a touch from a finger. You will either have to make it so that all touches draw

What's the right memory management pattern for buffer->CGImageRef->UIImage?

末鹿安然 提交于 2019-12-03 17:12:36
问题 I have a function that takes some bitmap data and returns a UIImage * from it. It looks something like so: UIImage * makeAnImage() { unsigned char * pixels = malloc(...); // ... CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, pixels, pixelBufferSize, NULL); CGImageRef imageRef = CGImageCreate(..., provider, ...); UIImage * image = [[UIImage alloc] initWithCGImage:imageRef]; return [image autorelease]; } Can anyone explain exactly who owns what memory here? I want to clean up

CGContextClipToMask returning blank image

て烟熏妆下的殇ゞ 提交于 2019-12-03 11:57:28
I'm new to Quartz. I have 2 images, a background, and a mask with cutout shape that I want to lay over the background in order to cut out a section. The resulting image should be the shape of the cutout. This is my mask (the shape in the middle is 0 alpha): And this is my code: UIView *canvas = [[[sender superview] subviews] objectAtIndex:0]; UIGraphicsBeginImageContext(canvas.bounds.size); CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef cgContext = CGBitmapContextCreate(NULL, canvas.bounds.size.width, canvas.bounds.size.height, 8, 0, colourSpace,