core-graphics

Cropping a UIImage according to the viewport inside a UIScrollView

安稳与你 提交于 2020-01-01 07:00:05
问题 I have a UIImageView (initialized with Aspect Fill) inside a UIScrollView. The user shall use that to resize and position a UIImage to his like, press a button and then exactly what he sees on screen would be sent to a server, only in the original image coordinates. In other words, the resulting image would be bigger than the image on screen. Here's the essential part of my code so far: // select the original CGFloat imageRatio = self.imageView.image.size.width / self.imageView.image.size

Point inside a rotated CGRect

半腔热情 提交于 2020-01-01 05:36:22
问题 How would you properly determine if a point is inside a rotated CGRect/frame? The frame is rotated with Core Graphics. So far I've found an algorithm that calculates if a point is inside a triangle, but that's not quite what I need. The frame being rotated is a regular UIView with a few subviews. 回答1: Let's imagine that you use transform property to rotate a view: self.sampleView.transform = CGAffineTransformMakeRotation(M_PI_2 / 3.0); If you then have a gesture recognizer, for example, you

iPhone iOS how to flip/reflect any UIView in - place?

我的未来我决定 提交于 2020-01-01 05:10:07
问题 I know how to flip/reflect/rotate a UIImage by re-drawing it within it's bounds. - (IBAction)reflectImageView:(UIImageView)imageView { UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 0.0); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextScaleCTM(context, 1.0, -1.0); CGContextTranslateCTM(context, 0.0, -imageView.bounds.size.height); [imageView.layer renderInContext:context]; imageView.image = UIGraphicsGetImageFromCurrentImageContext();

Mac OS X Window Server vs. X11: the insane task

♀尐吖头ヾ 提交于 2020-01-01 03:23:08
问题 Dedicated to all who likes low-level Window Server (CoreGraphicsPrivate.h, etc), X11 on Mac, SIMBL and other crazy stuff :) There's a simple X11-emulated application on Mac (like xterm, xeyes and so on) with one window. While running, X11 somehow creates a native Quartz window to represent this emulated application, and this window is accessible via Quartz Window Services so that I can get its CSWindowID, title, position, size and owner's PID (PID of X11.app). But it does not support

How to flip coordinates when drawing in context?

人走茶凉 提交于 2020-01-01 02:41:06
问题 I create a context from an UIImage, and then I draw into it with CGContextDrawImage(bitmapContext, CGRectMake(0, 0, originalImage.size.width, originalImage.size.height), oImageRef); the image appears upside-down due to the flipped coordinate system in quartz. How can I fix that? 回答1: You should be able to transform the context using something similar to the following: CGContextSaveGState(bitmapContext); CGContextTranslateCTM(bitmapContext, 0.0f, originalImage.size.height); CGContextScaleCTM

Getting pixel format from CGImage

佐手、 提交于 2019-12-31 22:27:15
问题 I understand bitmap layout and pixel format subject pretty well, but getting an issue when working with png / jpeg images loaded through NSImage – I can't figure out if what I get is the intended behaviour or a bug. let nsImage:NSImage = NSImage(byReferencingURL: …) let cgImage:CGImage = nsImage.CGImageForProposedRect(nil, context: nil, hints: nil)! let bitmapInfo:CGBitmapInfo = CGImageGetBitmapInfo(cgImage) Swift.print(bitmapInfo.contains(CGBitmapInfo.ByteOrderDefault)) // True My

How to give “locations” to CAGradientLayer

允我心安 提交于 2019-12-31 12:53:33
问题 I have created CAGradientLayer having three colors, i need to give each color different locations. Example: Red = 0 to 50 % Yellow = 51 to 80 % Green = 81 to 100 % I have tried with giving startPoint and endPoint but it did not work. 回答1: If you put the following code into a Playground you will get the exact desired output: let view = UIView(frame: CGRectMake(0,0,200,100)) let layer = CAGradientLayer() layer.frame = view.frame layer.colors = [UIColor.greenColor().CGColor, UIColor.yellowColor(

How to give “locations” to CAGradientLayer

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-31 12:52:15
问题 I have created CAGradientLayer having three colors, i need to give each color different locations. Example: Red = 0 to 50 % Yellow = 51 to 80 % Green = 81 to 100 % I have tried with giving startPoint and endPoint but it did not work. 回答1: If you put the following code into a Playground you will get the exact desired output: let view = UIView(frame: CGRectMake(0,0,200,100)) let layer = CAGradientLayer() layer.frame = view.frame layer.colors = [UIColor.greenColor().CGColor, UIColor.yellowColor(

Using Core animation to animate StrokeColor

£可爱£侵袭症+ 提交于 2019-12-31 02:07:22
问题 I'm trying to animate CAShapeLayar's strokeColor property. I looked throught the documentation and it was stated that it is an animatable property. The code is working for animating postion.y but not the the strokeColor. I'll be happy to get any kind of help or advice The code I've used: lyr.fillColor = [[UIColor clearColor] CGColor]; lyr.lineWidth = 3.8; lyr.strokeColor = [[UIColor yellowColor] CGColor]; lyr.position = CGPointMake(160, 431); lyr.anchorPoint = CGPointMake(.5f, .5f); [self

Xcode 8 Beta 4 CGColor.components unavailable

烈酒焚心 提交于 2019-12-31 01:48:13
问题 Whilst the code below worked previously, it has stopped working in Xcode 8 Beta 4, presumably because the components return was a very un-Swift-y C-array of floats, and has been removed. The error is bald - "'components' is unavailable" - and I can't find what has replaced it, if anything. Does anyone know how to produce the same functionality? public var cgColour: CGColor { get { return CGColor(red: self.colourRed, green: self.colourGreen, blue: self.colourBlue, alpha: self.colourAlpha) }