core-graphics

Creating Gif Image Color Maps in iOS 11

不羁岁月 提交于 2019-12-12 08:26:38
问题 I recently was having an issue when creating a Gif where if it got too big colors went missing. However thanks to help from SO someone was able to help me find a work around and create my own color map. Previous Question here...iOS Colors Incorrect When Saving Animated Gif This worked great up until iOS 11. I can't find anything in the docs that changed and would make this no longer work. What I have found is if I remove kCGImagePropertyGIFImageColorMap A gif is generated but it has the

Getting NSImage from CGImageRef

旧街凉风 提交于 2019-12-12 08:19:59
问题 I am trying process an image in CoreGraphics and then return the processed image back to an NSImage for saving and displaying. I have ample resources on how to perform these functions in iOS but the helper methods seem to be missing in NSImage . In iOS the class method is imageWithCGImage: , how can you do this in Mac OS? 回答1: The matching method in NSImage is initWithCGImage:size: . The second argument takes the image's size in points. The factor between the size in pixels (of the CGImage)

What is the right way of creating circle animation?

老子叫甜甜 提交于 2019-12-12 08:18:29
问题 I just saw this image and it's interesting to me, how to create such type of animation in Swift: So, I have many gray teeth in circle and when I set the angle, for example 45degree it will fill these gray teeth into blue within 0..45 degree. You can just explain me the right way of doing it or you can show different snippets(it would be great). And later I will search or read about it. Thanks in advance! 回答1: If you only need the individual 'teeth' to change color, instead of using the teeth

In this CGBitmapContextCreate, why is bytesPerRow 0?

ε祈祈猫儿з 提交于 2019-12-12 07:37:50
问题 I've noticed in Apple's sample code that they often provide a value of 0 in the bytesPerRow parameter of CGBitmapContextCreate. For example, this comes out of the Reflection sample project. CGContextRef gradientBitmapContext = CGBitmapContextCreate(NULL, pixelsWide, pixelsHigh, 8, 0, colorSpace, kCGImageAlphaNone); That seemed odd to me, since I've always gone the route of multiplying the image width by the number of bytes per pixel. I tried swapping in a zero into my own code and tested it

Core Graphics angle gradient for gauge

蓝咒 提交于 2019-12-12 06:47:57
问题 I'm trying to apply an angle gradient to the dashes created with the code I've written inside a custom UIView class, as below. Although it needs tweaking, I'm happy with the results it produces so far. Given the input parameters in the view initialisation (below), and a frame of 768 * 768 on an iPad Air2 in portrait mode, it produces the following gauge: First gauge What I'd like to do is to cause each of the dashes to step through a user-defined gradient, e.g. green to red, much like this

VNFaceObservation BoundingBox Not Scaling In Portrait Mode

老子叫甜甜 提交于 2019-12-12 05:59:43
问题 For reference, this stems from a question in the Vision API . I am working to use Vision to detect faces in an image via a VNDetectFaceRectanglesRequest , which is successfully functioning in terms of determining the correct number of faces in an image and providing the boundingBox for each face. My trouble is that due to my UIImageView (which holds the UIImage in question) is using a .scaleAspectFit content mode, I am having immense difficulty in properly drawing the bounding box in portrait

CGDisplayCaptureWithOptions (kCGDirectMainDisplay, kCGCaptureNoFill) still fills the screen with black

梦想与她 提交于 2019-12-12 05:38:26
问题 Hi I've recently been moving some of our old quickdraw code to use quartz and I've run into one little snag. According to the docs ("Display Capture Options" @ developer.apple.com) I can pass kCGCaptureNoFill as a parameter to CGDisplayCaptureWithOptions(), to disable filling the screen with black when it is captured. I'm using it like so: CGDisplayErr err = CGDisplayCaptureWithOptions (kCGDirectMainDisplay, kCGCaptureNoFill); if (err == kCGErrorSuccess) { etc... } But the screen is still

CGImageDestinationCreateWithData constants in iOS

谁都会走 提交于 2019-12-12 05:17:54
问题 I have the following code which turns a CGImage into NSData : import Foundation import CoreGraphics import ImageIO // ... snip ... let data = NSMutableData() if let dest = CGImageDestinationCreateWithData(data, kUTTypePNG, 1, nil), let image = self.backgroundImage { CGImageDestinationAddImage(dest, image, nil) if CGImageDestinationFinalize(dest) { return data as Data } } return nil The code compiles fine in Mac-OS, but kUTTypePNG is undefined in iOS. The actual value of the constant is

Getting a screenshot of a UIScrollView, including offscreen parts

自作多情 提交于 2019-12-12 05:16:02
问题 I have a UIScrollView decendent that implements a takeScreenshot method that looks like this: -(void)takeScreenshot { CGRect contextRect = CGRectMake(0, 0, 768, 1004); UIGraphicsBeginImageContext(contextRect.size); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // do something with the viewImage here. } This basically moves to the top of the scroll view, and takes a screenshot of the

How to mark points on a path drawn using CAShapeLayer - Swift?

一曲冷凌霜 提交于 2019-12-12 03:31:48
问题 I have a custom path drawn using CAShapeLayer in a UIView . Its a semicircle, upper half, drawn from left to right. Following is the code used, writted in a UIView subclass: func drawSemicircle() { // drawing an upper half of a circle -> 180 degree to 0 degree, clockwise let startAngle = CGFloat(M_PI) let endAngle = CGFloat(0.0) let centerPoint = CGPointMake(CGRectGetWidth(frame)/2 , CGRectGetHeight(frame)) // path set here let semirCircleLayer = CAShapeLayer() let semirCirclePath =