core-graphics

NSBitmapImageRep:colorAtX:y returned NSColor keeps growing on the heap

时光毁灭记忆、已成空白 提交于 2020-01-05 08:25:01
问题 I'm comparing the "color distance" between two images with the same width and height to see how similar they are - the measure of similarity is just comparing them pixel by pixel and seeing how far each of their color channels are from one another. - (NSNumber*) calculateFitness:(NSImage*)currentImage andDestinationImage:(NSImage*)destinationImage { NSData *tiffData = [currentImage TIFFRepresentation]; NSBitmapImageRep *currentImageRep = [NSBitmapImageRep imageRepWithData:tiffData]; NSData

Applying alpha outside intersection of 2 CGPath objects

限于喜欢 提交于 2020-01-05 07:26:33
问题 I have a CGPathRef for an oddly shaped polygon. I need to apply an alpha to the area outside of this path. This is pretty straightforward. CGContextAddPath(context, crazyPolygon); CGContextSetFillColor(context, someAlphaColor); CGContextEOFillPath(context); I need to do something similar with a circle, also straightforward. CGMutablePathRef circlePath = CGPathCreateMutable(); CGPathAddRect(circlePath, NULL, rect); CGPathAddEllipseInRect(circlePath, NULL, circleBox); CGContextAddPath(context,

Blurred Screenshot of a view being drawn by UIBezierPath

☆樱花仙子☆ 提交于 2020-01-05 06:55:30
问题 I'm drawing my graph view using UIBezierPath methods and coretext. I use addQuadCurveToPoint:controlPoint: method to draw curves on graph. I also use CATiledLayer for the purpose of rendering graph with large data set on x axis. I draw my whole graph in an image context and in drawrect: method of my view I draw this image in my whole view. Following is my code. - (void)drawImage{ UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0.0); // Draw Curves [self drawDiagonal]; UIImage

Blurred Screenshot of a view being drawn by UIBezierPath

我的未来我决定 提交于 2020-01-05 06:55:28
问题 I'm drawing my graph view using UIBezierPath methods and coretext. I use addQuadCurveToPoint:controlPoint: method to draw curves on graph. I also use CATiledLayer for the purpose of rendering graph with large data set on x axis. I draw my whole graph in an image context and in drawrect: method of my view I draw this image in my whole view. Following is my code. - (void)drawImage{ UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0.0); // Draw Curves [self drawDiagonal]; UIImage

MacOS: Add a text overlay to an image in Swift

非 Y 不嫁゛ 提交于 2020-01-05 04:36:09
问题 I've written a small extension for UIImage, which adds a text to an image: extension UIImage { func addTextToImage(textToAdd: String) -> UIImage { let textColor = UIColor.white let textFont = UIFont(name: "Snell Roundhand", size: 40)! let scale = UIScreen.main.scale UIGraphicsBeginImageContextWithOptions(self.size, false, scale) let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = NSTextAlignment.center var textFontAttributes = [ NSAttributedString.Key.font: textFont,

What is causing this edge condition with CGContextAddArc?

你离开我真会死。 提交于 2020-01-04 15:16:30
问题 I created a view by drawing an arc of dots around the perimeter of a circle using iOS Core Graphics. Dot centres are calculated, stored in an array and retrieved using CGContextAddArc before being rendered to screen. I have every confidence in methods used to draw perimeter dots which may be [A] outlined, [B] filled with one colour, [C] alternately filled and outlined, and [D] filled with a sequence of five colours as shown. However if centre dots are added to the array the properties of the

UIGraphicsGetCurrentContext didn't appear inside UIView

若如初见. 提交于 2020-01-04 13:47:54
问题 I have to draw a shape and detect if user touches are inside the shape or not, so I defined a custom class inherit from UIView as follow : class ShapeView: UIView { override init(frame: CGRect) { super.init(frame: frame) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func draw(_ rect: CGRect) { drawShape() } func drawShape() { guard let ctx = UIGraphicsGetCurrentContext() else { return } let zero = CGPoint(x: frame.midX, y: frame

UIGraphicsGetCurrentContext didn't appear inside UIView

三世轮回 提交于 2020-01-04 13:47:16
问题 I have to draw a shape and detect if user touches are inside the shape or not, so I defined a custom class inherit from UIView as follow : class ShapeView: UIView { override init(frame: CGRect) { super.init(frame: frame) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func draw(_ rect: CGRect) { drawShape() } func drawShape() { guard let ctx = UIGraphicsGetCurrentContext() else { return } let zero = CGPoint(x: frame.midX, y: frame

Is it possible to resize a UIImage without losing quality?

半世苍凉 提交于 2020-01-04 06:04:09
问题 I have a UIImage that I put in a UIImageView which has a pinch gesture recognizer attached to it which I use to scale the image. When I scale the image in the UIImageView, there is no distortion and it scales perfectly. However, I need to resize the UIImage while not in the UIImageView, and when I do this using the following code, the result is slightly skewed: CGFloat width = self.imageView.frame.size.width; CGFloat height = self.imageView.frame.size.height; UIGraphicsBeginImageContext

How to get Window reference (CGWindow, NSWindow or WindowRef) from CGWindowID in Swift?

ε祈祈猫儿з 提交于 2020-01-04 05:34:08
问题 How to get Window reference (CGWindow, NSWindow or WindowRef) from CGWindowID in Swift on XCode 7.3 Mac Playground? I referenced from Apple's document - Window Manager Reference, and from the sample code SonofGrab, but I didn't find an answer in obj-C nor Swift. How should I do it? 回答1: This should work for NSWindow from CGWindowID NSWindow * ns_window; ns_window = [NSApp windowWithWindowNumber: windowNumber]; To get CGWindowID from NSWindow use CGWindowID window_id = (CGWindowID)[ns_window