core-graphics

Can I draw to the same CGContextRef from multiple threads?

依然范特西╮ 提交于 2020-01-23 02:12:12
问题 I'm making an app where I want to draw a lot of shapes - circles, boxes, lines, etc. Millions of them. To test the performance of this, I threw together this simple UIView. Note that credit is due - I got inspired by this project. import UIKit let qkeyString = "label" as NSString var QKEY = qkeyString.UTF8String let qvalString = "com.hanssjunnesson.Draw" as NSString var QVAL = qvalString.UTF8String public class RenderImageView: UIView { var bitmapContext: CGContext? let drawQueue: dispatch

How do you generate an RGBA image in Core Graphics?

霸气de小男生 提交于 2020-01-21 06:51:10
问题 I'm trying to generate an RGBA8 image from text to use as an OpenGL ES 2.0 texture. +(UIImage *)imageFromText:(NSString *)text { UIFont *font = [UIFont systemFontOfSize:20.0]; CGSize size = [text sizeWithFont:font]; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef contextRef = CGBitmapContextCreate (NULL, size.width, size.height, 8, 4*size.width, colorSpace, kCGImageAlphaLast ); CGColorSpaceRelease(colorSpace); UIGraphicsPushContext(contextRef); [text drawAtPoint

How to set a gradient border on UIView?

拟墨画扇 提交于 2020-01-20 19:42:49
问题 It's very easy to put a simple border on a UIView . You simply link to QuartzCore , import it, and use: self.view.layer.borderColor = [UIColor redColor].CGColor; self.view.layer.borderWidth = 2.0f; My question is... Is there a way to make this border use a gradient. I know how to apply a gradient mask to the entire view, but not just to its border. I'm assuming this could involve a custom view and CoreGraphics drawing inside drawRect: , but I'm not sure where to start. 回答1: I'm not entirely

How to effectively process UITouches in a multitouch sequence

一曲冷凌霜 提交于 2020-01-19 04:04:38
问题 I am working with multitouch while writing, So basically what I am doing is, I am writing with hand support, because typically, its how user writes, I followed this link How to ignore certain UITouch Points in multitouch sequence Everything is working fine with single touch, but their is some problem when I write with my hand touching the screen i.e multiple UItouches Below is my code In touches began, I go through all touches and I find the touch with highest y position, below is my code

getting the text up-side down in core graphic

*爱你&永不变心* 提交于 2020-01-16 19:57:48
问题 I am drawing a text in core graphic by following - (void)drawRect:(CGRect)rect { CGContextTranslateCTM(context, 20, 150); CGContextScaleCTM(context, 1, 1); // Draw the text using the MyDrawText function myDrawText(context, viewBounds); } void myDrawText (CGContextRef myContext, CGRect contextRect) { CGFloat w, h; w = contextRect.size.width; h = contextRect.size.height; CGAffineTransform myTextTransform; CGContextSelectFont (myContext, "Helvetica-Bold", h/12, kCGEncodingMacRoman);

getting the text up-side down in core graphic

99封情书 提交于 2020-01-16 19:57:27
问题 I am drawing a text in core graphic by following - (void)drawRect:(CGRect)rect { CGContextTranslateCTM(context, 20, 150); CGContextScaleCTM(context, 1, 1); // Draw the text using the MyDrawText function myDrawText(context, viewBounds); } void myDrawText (CGContextRef myContext, CGRect contextRect) { CGFloat w, h; w = contextRect.size.width; h = contextRect.size.height; CGAffineTransform myTextTransform; CGContextSelectFont (myContext, "Helvetica-Bold", h/12, kCGEncodingMacRoman);

bezierPathWithRoundedRect not perfect circle

女生的网名这么多〃 提交于 2020-01-16 06:09:05
问题 I have some problem with draw circle: This simply code demonstrates that: - (void)drawRect:(CGRect)rect { self.layer.sublayers = nil; CGFloat radius = self.frame.size.width/2; circle = [CAShapeLayer layer]; circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.width) cornerRadius:radius].CGPath; circle.fillColor = [UIColor clearColor].CGColor; circle.strokeColor = [UIColor redColor].CGColor; circle.lineWidth = 4; [self.layer addSublayer

Render a CGImage (rather than UIImage) directly?

人走茶凉 提交于 2020-01-16 02:26:44
问题 I'm making a CGImage func otf() -> CGImage { which is a bezier mask on a gradient. So, // the path let p = UIBezierPath() p.moveTo etc // the mask let m = CAShapeLayer() set size etc m.path = p.cgPath // the layer let l = CAGradientLayer() set colors etc l.mask = m it's done. So then render a UIImage in the usual way ... UIGraphicsBeginImageContextWithOptions(sz.size, false, UIScreen.main.scale) l.render(in: UIGraphicsGetCurrentContext()!) let r = UIGraphicsGetImageFromCurrentImageContext()!

Core Graphics - how to crop non-transparent pixels out of a UIImage?

蓝咒 提交于 2020-01-15 10:54:11
问题 I have a UIImage that is reading from a transparent PNG (500px by 500px). Somewhere in the image, there is a picture that I want to crop out and save as a separate UIImage. I also want to store the X and Y coordinates based on how many transparent pixels there were on the left and top of the newly cropped rectangle. I was able to crop an image with this code: - (UIImage *)cropImage:(UIImage *)image atRect:(CGRect)rect { double scale = image.scale; CGRect scaledRect = CGRectMake(rect.origin.x

How to give 3D effects to UIImageView/uiview using OpenGL looks like a 3D CUBE

别来无恙 提交于 2020-01-15 10:17:11
问题 I am new to OpenGL and don't much have knowledge in it. I want to add a 3D effect to a UIImageView . How can I achieve this using OpenGL? I want to do something like seen in this image: I have searched and found that it is possible using OpenGL. I have referred to this link With OpenGL . I have created a cube, and got some effect with glDrawElements(GL_TRIANGLES, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0); But I come to know with glDrawRangeElements we can make a 3d cube, But I