core-graphics

how to optimized this image processing replace all pixels on image with closest available RGB?

谁都会走 提交于 2019-12-13 01:27:30
问题 Im' trying to replace all pixels of input image with closest available RGB. I have a array contain color and input image. Here is my code, it give me an output image as expected, BUT it take very LONG time( about a min) to process one image. Can anybody help me improve the code? Or if you have any other suggestions, please help. UIGraphicsBeginImageContextWithOptions(CGSizeMake(CGImageGetWidth(sourceImage),CGImageGetHeight(sourceImage)), NO, 0.0f); //Context size I keep as same as original

Getting the average RGB color of a CGImageRef in iOS

女生的网名这么多〃 提交于 2019-12-13 00:57:55
问题 I've been struggling with this for a couple of hours, and I'm hoping someone else has some insight. I'm looking for a way to get the average RGB color of a 1x1 UIImage. So far I've created a CGImageRef from the UIImage, but I'm really new to CoreGraphics, so I'm not sure where to go from there. Any help is appreciated. Thanks! 回答1: If you have a CGImage, you get the data by calling CGDataProviderRef CGImageGetDataProvider ( CGImageRef image ); CGImage doc Then you can copy the data CFDataRef

Controlling level and focus of windows other apps with CGPrivate functions

自古美人都是妖i 提交于 2019-12-13 00:53:33
问题 Question How to use these private functions on other windows? It would be nice to have this knowledge back in the wild. I am specifically trying to get CGSOrderWindow and CGSSetWindowLevel to work. I was trying in the direction of: temporarily register as the dock and then register the dock as the dock again immediately afterwards or code injection into the Dock process per this comment: Also, the author of the above project seems determined to make all core functionality available as a

imageWithCGImage: GCD memory issue

梦想与她 提交于 2019-12-13 00:48:10
问题 When I perform the following only on the main thread iref gets autoreleased immediately: -(void)loadImage:(ALAsset*)asset{ @autoreleasepool { ALAssetRepresentation* rep = [asset defaultRepresentation]; CGImageRef iref = [rep fullScreenImage]; UIImage* image = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:UIImageOrientationUp]; [self.imageView setImage:image]; } } But when I perform imageWithCGImage: with GCD on a background thread iref does not get released instantly like in

NSTimer on device is slower than in simulator

送分小仙女□ 提交于 2019-12-12 21:25:10
问题 I am new to iPhone development. I used [NSTimer scheduledTimerWithTimeInterval:0.01] for game loop. The game consists drawscreen function in which I use CGContextClipToRect to clip the large images for animation. But the speed 0.01 seconds is working in simulator only not on device. How can I overcome this problem? The timer code is in view controller as (void)viewDidLoad { GameView *main = [[GameView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; main.backgroundColor =

CAGradient layer not visible on view

我是研究僧i 提交于 2019-12-12 21:01:02
问题 I try to add a CAGradient effect in a pie chart I make with Core Graphics. It turns out I am not able and certainly not understand very well how to apply it to a view that is part of a CGPath... override func draw(_ rect: CGRect) { ... func arc(myRadius: CGFloat, myStartAngle: CGFloat, myEndAngle: CGFloat) { // This is the pie chart segment context?.setFillColor(phenotypeColor.cgColor) context?.move(to: center) context?.addArc(center: center, radius: finalRadius, startAngle: myStartAngle,

How to resize CIImage?

眉间皱痕 提交于 2019-12-12 19:52:11
问题 I need to resize more image in one "for" but if I use UIGraphicsGetImageFromCurrentImageContext, I don't have enough memory for more images, because it stay on autorelease and images released when "for" is terminated. I need another method for resize. Any ideas. Thanks -(UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize { CGSize targetSize = newSize; CGSize imageSize = image.size; CGFloat width = imageSize.width; CGFloat height = imageSize.height; CGFloat targetWidth =

Calling layer.setNeedsDisplay() shows a black background

ε祈祈猫儿з 提交于 2019-12-12 19:05:08
问题 When I call setNeedsDisplay() on my UIView's CALayer (either directly, or via needsDisplayOnBoundsChange ), it draws the background as black. myView.layer.setNeedsDisplay() When I call 'setNeedsDisplay()' on the UIView directly, it doesn't show up as black: myView.setNeedsDisplay() Why does this happen, and how can I fix it? 回答1: The problem was that my view's background color was somehow set to nil instead of .white or .clear , for example. It seems odd that this happens only when calling it

Fastest way to draw offscreen CALayer content

懵懂的女人 提交于 2019-12-12 18:54:38
问题 I'm looking for the fastest way to draw offscreen CALayer content (no alpha needed) on macOS. Note, that these examples aren't threaded, but the point is (and why I'm not just using CALayer.setNeedsDisplay) because I'm doing this drawing on a background thread. My original code did this: let bounds = layer.bounds.size let contents = NSImage(size: size) contents.lockFocusFlipped(true) let context = NSGraphicsContext.current()!.cgContext layer.draw(in: context) contents.unlockFocus() layer

CGContextRef - EXC_BAD_ACCESS Error [duplicate]

情到浓时终转凉″ 提交于 2019-12-12 17:31:25
问题 This question already has answers here : Assigning an existing CGColor to a CGColor property works in iOS Simulator, not iOS device. Why? (3 answers) Closed 6 years ago . I am subclassing UIView and using instances of that to set my UITableViewCell backgroundView and selectedBackedView properties. I am receiving an EXC_BAD_ACCESS error in the drawRect method of my UIView subclass. if(nil == cell){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier