cgcontext

Stroke a CGContext path using an image in CoreGraphics

风格不统一 提交于 2019-12-10 00:28:34
问题 Im trying to draw line by stroking an image to have brush like effect via CoreGraphics framework. I followed this post and this post and tried to draw from the touchesMoved method and the code sample'll be of the form UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self.view]; UIImage *texture = [UIImage imageNamed:@"texture.png"]; CGPoint vector = CGPointMake(currentPoint.x - lastPoint.x, currentPoint.y - lastPoint.y); NSLog(@" vector %@",

Memory consumption spikes when resizing, rotating and cropping images on iPhone

女生的网名这么多〃 提交于 2019-12-09 23:34:22
问题 I have an "ImageManipulator" class that performs some cropping, resizing and rotating of camera images on the iPhone. At the moment, everything works as expected but I keep getting a few huge spikes in memory consumption which occasionally cause the app to crash. I have managed to isolate the problem to a part of the code where I check for the current image orientation property and rotate it accordingly to UIImageOrientationUp . I then get the image from the bitmap context and save it to disk

Swift - Using CGContext to draw with finger

给你一囗甜甜゛ 提交于 2019-12-09 07:18:28
问题 I'm trying to make a drawing app. I have a single custom UIView: class DrawView: UIView { var touch : UITouch! var lastPoint : CGPoint! var currentPoint : CGPoint! override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { touch = touches.first as! UITouch lastPoint = touch.locationInView(self) println(lastPoint) } override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) { touch = touches.first as! UITouch currentPoint = touch.locationInView(self) self

iphone MPMoviePlayerViewController CGContext Errors

霸气de小男生 提交于 2019-12-09 05:29:39
问题 I am writing an app for the iPhone that will play some movies utilizing MPMoviePlayerViewController . So far I have gotten it to play movies, however it is throwing some errors in the debugger that all start with CGContext . I have wracked my brain in trying to fix it. Here are the details of my code: .h file: #import <UIKit/UIKit.h> #import <MediaPlayer/MediaPlayer.h> @interface MovieViewController : UIViewController { MPMoviePlayerViewController *playerController; } -(IBAction) playMovie:

When is -[UIView drawRect:] Method Invoked?

谁说胖子不能爱 提交于 2019-12-08 19:16:43
问题 Is it invoked just before the main view is going to be shown Can we call it whenever we want? 回答1: It's called whenever the view or part of the view needs to be drawn or redrawn. It's called when you first display the view. It's called when you alter the view. In the life cycle of a view, it may be called hundreds or even thousands of times. For example, in a text view, it is called every time a new text character is entered. Any change in the program state that the view must reflect visually

How to render UIView into a CGContext

五迷三道 提交于 2019-12-08 16:10:23
问题 I Wanted to render a UIView into a CGContextRef -(void)methodName:(CGContextRef)ctx { UIView *someView = [[UIView alloc] init]; MagicalFunction(ctx, someView); } So, the MagicalFunction here is supposed to render the UIView(may be its layer) into current context. How do I do that? Thanks in advance! 回答1: How about the renderInContext method of CALayer? -(void)methodName:(CGContextRef)ctx { UIView *someView = [[UIView alloc] init]; [someView.layer renderInContext:ctx]; } EDIT: As noted in the

Showing actionsheet causes CGContext invalid context errors

半腔热情 提交于 2019-12-08 06:54:42
问题 I'm using actionsheet to display lists of data for the user to choose from. The problem is that showing the actionsheet using [self.actionSheet showInView:self.view]; is causing several CGContext errors. The same code worked well in iOS 6. Code: self.actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; [self.actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque]; CGRect tableFrame = CGRectMake(0,

Drawing with with blur effect on image using opengl

旧时模样 提交于 2019-12-08 05:26:35
问题 I have the same requirement as this question I am right now at situation where i set UIImage on my opengl view. Below is the complete code i used to set uiimage. Also it includes the drawing code. Using below code I am able to set image and drawing on it. when i do not set image in background it allows me to draw blur and smooth drawing but if i set background image it draws solid drawing I want smooth drawing on background image. I have used some of GLPaint code of apple for drawing. - (id

How to draw a triangle shaped UIButton

家住魔仙堡 提交于 2019-12-07 21:35:29
问题 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! 回答1: First use a CAShapeLayer to create a mask CAShapeLayer * shapeLayer = [CAShapeLayer layer]; //Use these to create path CGMutablePathRef path = CGPathCreateMutable(); // CGPathMoveToPoint // CGPathAddLines

How to draw a UILabel with a different blend mode in draw(_ rect: CGRect) in Swift

一曲冷凌霜 提交于 2019-12-07 18:08:59
问题 So I have a UILabel that is being drawn on top of a gradient image (that is a UIImageView ). It looks sorta like this: I'm trying to change the blendMode of the graphics context in the UILabel 's draw(_ rect: CGRect) function so that it draws the label but blended with the background with a softLight blending mode. Here is what I want it to look like: Here is the code I have in the draw(_ rect: CGRect) function: override func draw(_ rect: CGRect) { // Drawing code if let context =