core-graphics

How to encode UIBezierPath to SVG?

依然范特西╮ 提交于 2019-12-06 11:16:36
I have a simple view for finger painting / drawing. I store the drawings as UIBezierPath s in a NSMutableArray . Now I want to transfer the drawings to a web-service for presenting them in a browser. Therefore I need to encode my UIBezierPath s in a SVG-file - because this the format of the web-service. What I found right now is the SVGKit , which only DECODES SVG. Do anybody know sample code, snippets or a framework for encoding SVG? Thank you. bitmapdata.com I tested yet. but using following steps: Would not it be possible? 1.UIBezierPath to CGPathRef. UIBezierPath to CGPathRef 2.Using a

How to draw a triangle shaped UIButton

99封情书 提交于 2019-12-06 10:41:59
I really dig the IFTTT bottom right corner button, as shown in the image (bottom right). I tried playing around with CGContext and UIBezierPath to match the effect, but i simply don't know enough to get this right. Does anyone have some thoughts/code on how to make this happen? Thanks! First use a CAShapeLayer to create a mask CAShapeLayer * shapeLayer = [CAShapeLayer layer]; //Use these to create path CGMutablePathRef path = CGPathCreateMutable(); // CGPathMoveToPoint // CGPathAddLines shapeLayer.path = path; Then set mask of your button yourbutton.layer.mask = shapeLayer yourbutton

App crashes when using __bridge for CoreGraphics gradient on ARC

丶灬走出姿态 提交于 2019-12-06 10:38:08
I'm creating an application for iOS 5 and I'm drawing some gradients. The following gradient code I've always used before ARC, but now it does not work on my device anymore (however, it works on the simulator) when I use it several times (so I suppose it's a memory management issue). Anyways, here's the code: CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGFloat locations[] = { 0.0, 1.0 }; NSArray *colors = [NSArray arrayWithObjects:(__bridge id)startColor, (__bridge id)endColor, nil]; CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors,

Resize UIImage under memory constraints

隐身守侯 提交于 2019-12-06 09:42:11
I have a massive UIImage downloaded from a web resource (>300MBs) which when I attempt to render is causing an app crash due to memory. I am trying to resize the image using the following code: + (UIImage *)imageWithImage:(UIImage *)image scaled:(float) scale { //UIGraphicsBeginImageContext(newSize); CGSize size = (CGSize){scale * image.size.width, scale * image.size.height}; UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return

iPhone UIView replace image color programmatically, like in Photoshop or Illustrator

怎甘沉沦 提交于 2019-12-06 08:39:30
问题 I have a set of graphics that I would like to reuse within my apps. They are buttons and images with transparency. Rather than having dozens of hard-coded button images, I would love to have a single button image, and be able to assign a color to it dynamically, like the navigation bar and it's tint color. Is it possible to replace/shift the hue of a UIView? Alternatively: I know that if I overlay a transparent image over another UIView, then I can change the background color and the two

How to create a perfect half circle with CGPathAddCurveToPoint?

南笙酒味 提交于 2019-12-06 08:22:50
问题 I am trying to create a perfect right half circle of 15 points radius with CGPathAddCurveToPoint, like this: CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddCurveToPoint(path, NULL, 15, 0, 15, 30, 0, 30); It starts at the top middle of the circle. Then the first control point is set to the top right corner of the circle's bounding box. The second control point is set to the bottom right corner of the circle's bounding box. The circle ends at bottom middle of the bounding box. But when drawn,

How to set the colors in glowing effect of a UILabel?

青春壹個敷衍的年華 提交于 2019-12-06 08:08:55
问题 We can typically set fontColor of a UILabel by: label.textColor = self.someTextColor; and the shadow (glow) by: label.layer.shadowColor = self.someGlowColor; label.layer.shadowOffset = CGSizeMake(0.0, 0.0); label.layer.shadowRadius = 3.0; label.layer.shadowOpacity = 0.5; It'ok for simple shadow. However, how can I set the font color with some fancy glowing effect? For example: Provided A is the color at center, B is color at font boundary, and C the glow effect. How can I use iOS API to

AVFoundation - Get grayscale image from Y plane (kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)

雨燕双飞 提交于 2019-12-06 08:01:03
问题 I'm using AVFoundation to take a video and I'm recording in kCVPixelFormatType_420YpCbCr8BiPlanarFullRange format. I want to make grayscale image directly from the Y plane of the YpCbCr format. I've tried to create CGContextRef by calling CGBitmapContextCreate , but the problem is, that I don't know what colorspace and pixelformat to choose. - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *

Making CIContext.render(CIImage, CVPixelBuffer) work with AVAssetWriter

為{幸葍}努か 提交于 2019-12-06 07:47:34
问题 I want to use Core Image for processing a bunch of CGImage objects and turning them into a QuickTime movie on macOS . The following code demonstrates what's needed, but the output contains a lot of blank (black) frames: import AppKit import AVFoundation import CoreGraphics import Foundation import CoreVideo import Metal // Video output url. let url: URL = try! FileManager.default.url(for: .downloadsDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent("av

How to find an arrow tip points given origin and end point of a line

江枫思渺然 提交于 2019-12-06 07:27:59
问题 Consider you have a line with start point (x1,y1) and end point (x2,y2). In order to draw an arrow cap to the line (in objective-c), I need to find the points of the arrow (x3,y3,x4,y4) given the angle of the arrow (45 degrees), and the length of the arrow tips (h). So given x1,y1,x2,y2,h,alpha whats x3,y3,x4,y4? Added an image explaining the question. If the answer can be in objective-c (using UIBezierpath and CGPoint) it will be much appreciated. Thanks! 回答1: #import <math.h> #import <UIKit