Saving CGImageRef to a png file?

Using CGImageDestination and passing kUTTypePNG is the correct approach. Here’s a quick snippet: @import MobileCoreServices; // or `@import CoreServices;` on Mac @import ImageIO; BOOL CGImageWriteToFile(CGImageRef image, NSString *path) { CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path]; CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL); if (!destination) { NSLog(@”Failed to create CGImageDestination for %@”, path); return NO; } … Read more

Implicit conversion from enumeration type ‘enum CGImageAlphaInfo’ to different enumeration type ‘CGBitmapinfo’ (aka) ‘enum CGBitmapInfo’)

From the docs: The constants for specifying the alpha channel information are declared with the CGImageAlphaInfo type but can be passed to this parameter safely. So you can just use a cast to suppress the warning: CGBitmapInfo bitmapInfo = (CGBitmapInfo) kBitmapInfo;

One step affine transform for rotation around a point?

A rotation of angle a around the point (x,y) corresponds to the affine transformation: CGAffineTransform transform = CGAffineTransformMake(cos(a),sin(a),-sin(a),cos(a),x-x*cos(a)+y*sin(a),y-x*sin(a)-y*cos(a)); You may need to plug in -a instead of a depending on whether you want the rotation to be clockwise or counterclockwise. Also, you may need to plug in -y instead of y depending on whether or … Read more

How to use kCGImagePropertyGIFImageColorMap or create a color table?

Core Graphics does not allow for the setting of a global color table, just a local color table for a single-image GIF file. Multi-image gif files require individual properties of each image to be set, which means the kCGImagePropertyGIFImageColorMap will have no effect when the source images are not themselves GIF files, and the code … Read more

CABasicAnimation does not animate correctly when I update model layer

I think that it’s easiest to explain what is happening for each of the three locations and then a “conclusion” at the end. I’m also adding some illustrations, showing exactly the behaviour that you are mentioning in your question so that it will be easier to follow for someone who hasn’t tried these three things … Read more

Weak performance of CGEventPost under GPU load

I guess you’re filling up the queue (underlying mach port)… You can confirm this using the “scheduling” or “system call” instrument in Instruments. (Create a new blank document, add the instrument, then under File > Record Options… make sure “deferred mode” is checked.) This will show all thread activity in your app (when threads block, … Read more

Create a rectangle with just two rounded corners in swift?

Swift 4+, iOS 11+ If you already have a UIView named myView referenced as an IBOutlet, try adding the following two lines in ViewDidLoad() or wherever it’s being loaded: myView.layer.cornerRadius = 10 myView.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner] You can change the array [] to any combination of MinX, MinY, MaxX, and MaxY to select the desired … Read more