quartz-graphics

CGImage (or UIImage) from a CALayer

三世轮回 提交于 2019-12-04 12:31:38
问题 I have created a CALayer (I added several shapes to the layer, but ultimately, I have a single CALayer), and I am having a LOT of trouble adding it to a CGImage. I have found some references to [CALayer renderInContext:ctx] , but I am not sure how to implement it. Has anyone done this before? 回答1: Try this... UIGraphicsBeginImageContext(layer.bounds.size); [layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

Is there a way to draw a CGContextDrawRadialGradient as an oval instead of a perfect circle?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 11:51:48
问题 I need a radial gradient in the shape of an oval or ellipse and it seems like it CGContextDrawRadialGradient can only draw a perfect circle. I've been drawing to a square context then copying/drawing into a rectangular context. Any better way to do this? Thanks! 回答1: The only way I've found to do this is as Mark F suggested, but I think the answer needs an example to be easier to understand. Draw an elliptical gradient in a view in iOS (and using ARC): - (void)drawRect:(CGRect)rect {

CGWindowListCopyWindowInfo, kCGWindowLayer and window level

限于喜欢 提交于 2019-12-04 10:49:33
The CGWindowLevel.h file defines the constants that are used to set the window level and the largest value that can be used as window level is 20. But, if you retrieve the window list using the call CGWindowListCopyWindowInfo , you can observe that the value of kCGWindowLayer is more than 20 (25, 103 etc). Aren't kCGWindowLayer and window level same? If they are not same, how do I get the window level for the windows that are obtained using CGWindowListCopyWindowInfo ? If they are same, why do we get value >20? It appears that kCGWindowLayer does refer to a window level, though I haven't found

Adding a mask with CALayers

我们两清 提交于 2019-12-04 10:27:39
问题 I seem to be having difficulties adding a mask via CALayers. I'm simply trying to mask a UIImageView. Here's my code: CALayer *maskLayer = [CALayer layer]; UIImage *mask = [UIImage imageNamed:@"mask.png"]; maskLayer.contents = mask; UIImageView *viewToMask = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; viewToMask.image = [UIImage imageNamed:@"picture.png"]; viewToMask.layer.mask = maskLayer; [self.view addSubview:viewToMask]; Mask.png is black with a transparent circle

Drawing on top of UIImageView to make the image transparent

天涯浪子 提交于 2019-12-04 10:15:36
I am working on one iPhone App wherein I need to make a portion of the image transparent by setting its alpha level to 0 as the user moves around his finger on the image. Basically if you happen to know the app store application iSteam, user should be able to move his finger around on a top image which will make the background image transparent. Currently I am using two UIImageView. One that holds the background image and the other on top of it which holds a darker image. Now user should be able to draw random curves on this darker image which will make the part of the background image appear

Sluggish scrolling experience when using QuartzCore to round corners on UIImageView's within a UITableViewCell

為{幸葍}努か 提交于 2019-12-04 08:25:01
I use QuartzCore to add rounded corners to my UIImageView 's within the cells of my UITableView This is the code that I use: fooImageView.layer.cornerRadius = 9.0; fooImageView.layer.masksToBounds = YES; fooImageView.layer.borderWidth = 1.0; The problem is that when I add this code. The table cells movement is slowed down dramatically. I'm just wondering whether there are other alternatives to make the user experience much faster and to increase performance when scrolling a table view cell using this technique? I see a lot of applications (most Twitter apps) that have no performance decrease

How do I remove those rotation artefacts from my CATiledLayer?

三世轮回 提交于 2019-12-04 07:21:29
I have a CATiledLayer into which I render content in the following method - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx I used the QuartzDemo code to draw a pattern. This works very well until I apply a rotation transform to the layer's parentLayer (a UIView): rotated: These zigzag artefacts become worse when I start drawing lines and texts into the CATiledLayer. I applied the transform as follows (I also tried using an affine transform on the view itself): self.containerView.layer.transform = CATransform3DMakeRotation(angleRadians, 0.0f, 0.0f, 1.0f); I transform the

CGContextClip() using an inverted path

余生长醉 提交于 2019-12-04 06:56:57
I want to have clipped drawing on my CGContext but I need it just the other way round, i.e. I want to add several rectangles to my clipping path using CGContextAddRect() and the clipping should be done in the way that all the rectangles that I have added to my clipping path stay unaffected by any drawing operations. Normally, it's just the other way round, i.e. drawing functions draw to the rectangles that have been added to the clipping path and leave the areas that haven't been added to the clipping path unaffected. So I guess what I need is just a way to reverse the clipping path before

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

How to determine and interpret the pixel format of a CGImage

我是研究僧i 提交于 2019-12-04 04:49:14
I'm loading this (very small) image using: UIImage* image = [UIImage named:@"someFile.png"]; The image is 4x1 and it contains a red, green, blue and white pixel from left to right, in that order. Next, I get the pixel data out of the underlying CGImage: NSData* data = (NSData*)CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage)); Now, for some reason, the pixel data is laid out differently depending on the iOS device. When I run the app in the simulator or on my iPhone 4, the pixel data looks like this: (255,0,0),(0,255,0),(0,0,255),(255,255,255) So, the pixels are 3 bytes per pixel,