core-graphics

Crop CMSampleBuffer and process it without converting to CGImage

痞子三分冷 提交于 2019-12-11 05:13:27
问题 I have been following the apple's live stream camera editor code to get the hold of live video editing. So far so good, but I need a way out to crop a sample buffer into 4 pieces and then process all four with different CIFilters. For instance, If the size of the image is 1000x1000, I want to crop the CMSampleBuffer into 4 images of size 250x250 and then apply unique filter to each, convert it back to CMSammpleBuffer and display on Metal View. Here is the code till which I could crop the

Triangle Gradient With Core Graphics

人走茶凉 提交于 2019-12-11 04:48:01
问题 I'm trying to draw a triangle like this one in a view (one UIView, one NSView): My first thought was CoreGraphics, but I couldn't find any information that would help me draw a gradient between three points of arbitrary color. Any help? Thanks! 回答1: Actually it's pretty simple with CoreGraphics. Below you can find code that renders given triangle, but first let's think how we can solve this problem. Theory Imagine equilateral triangle with side length w . All three angles are equal to 60

How to make universal round draws (with lineDashPattern) with UIbezierPath on Swift

*爱你&永不变心* 提交于 2019-12-11 04:29:57
问题 I'm about to make a universal Tuner app but when I try to draw an Analog meter it gets messed on different devices. Maybe it's very hardcoded.. Check this: The labels are under the same UIView too. Check the code to draw these paths: override func draw(_ rect: CGRect) { let center = CGPoint(x:bounds.width/2, y: bounds.height) var radius: CGFloat = max(bounds.width, bounds.height+50) // Define the thickness of the arc. let arcWidth: CGFloat = 1 let startAngle: CGFloat = π let endAngle: CGFloat

How to set up a clipping rectangle or area

眉间皱痕 提交于 2019-12-11 04:26:35
问题 How does one set up, modify, and clear a clipping rectangle inside a iOS drawRect for clipping generic CG drawing of lines, text, images, etc. to a small portion of a view? Is it possible to use a more complex clipping region that is a composite of a bunch of rectangles and circles? 回答1: You can set a clipping area with arbitrary paths, not restricted to rectangles. The followings are some ways of doing it: You can draw an arbitrary path and set a clipping area with it. For example:

ContentMode changes in uiimageview after draw

拟墨画扇 提交于 2019-12-11 04:19:53
问题 I have been following Ray Wenderlics's tutorial on how to create a basic draw app. Ive got it working perfectly except for when I draw the content mode changes on the uiimageview. I've set it to aspectFill in storyboard and applied an image I think the problem is in my touches ended method override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { if !swiped { // draw a single point drawLineFrom(fromPoint: lastPoint, toPoint: lastPoint) } // Merge tempImageView into

How can I improve CGContextFillRect and CGContextDrawImage performance

谁说我不能喝 提交于 2019-12-11 04:05:51
问题 Those two functions are currently my bottleneck. I am working with very large bitmaps. How can I improve their performance? 回答1: You could cache smaller versions of your bitmaps which you create before drawing the first time and then simply draw the downscaled samples instead of the full-blown 15 megapixel stuff. Then again make sure you are only drawing what is necessary i.e. in 'drawRect: (NSRect) rect' only draw inside the rect (unless absolutely necessary). And try not do perform drawings

Core-Graphics (iPhone) -Can we know whether a CGPath is closed?

一曲冷凌霜 提交于 2019-12-11 03:54:40
问题 Is there any workaround to know where a CGpath (created using an array of co-ordinates) is closed . I was not able to find any suitable method in the header CGPath . I wish to track the path traced by user .If its a closed loop, then i wish to extract that part from the context. Something like masking or clipping the context but it should be user tracked clipping. Thanks! 回答1: Just in case you've been stuck on this for the last 4 1/2 years, here is how to do it in Swift 3. I have borrowed

Why doesn't CGContextSetStrokeColorWithColor set text colour to black?

纵饮孤独 提交于 2019-12-11 03:04:02
问题 I have drawn text labels in front of a circular arc of dots using iOS Core Graphics. I am trying to understand why CGContextSetStrokeColorWithColor does not set text colour to black in the two examples below. Text labels are black if the dots are outlined. But when images are filled the text changes to the dot colour. EDIT: *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The suggestion of Ben Zotto helped to resolved this issue. In the original code below the solution was to replace

masking UIView based on CGRect

时间秒杀一切 提交于 2019-12-11 02:49:17
问题 Look at the image please : I have UIView and CGRect. I have to check where CGRect overlays UIView and then set the mask on the area which is "opposed" to intersection. So it's blue part in the image. How to achieve that? I know there's CGContextClipToMask but I have no idea how to use that - could someone help me with example code? Is CGContextClipToMask good direction? Thanks! 回答1: You can assign mask layer to your UIView's layer. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; view

How does drawRect and CGGraphicsContext work?

三世轮回 提交于 2019-12-11 02:46:42
问题 I am working with some stuff in Core Graphic's and I am looking for some additional clarification regarding a couple of topics. drawRect: I have an understanding of this and know it is where all of the drawing aspect's of a UIView goes, but am just unclear as to what is happening behind the scene's. What happen's when I create a UIView and fill out drawRect then set another object's UIView to be that custom view? When is drawRect being called? CGGraphicsContext: I know what the purpose of