Ios (Quartz 2D drawing) Various plotting methods and camera usage

Source: Internet
Author: User

Ios (Quartz 2D drawing) Various plotting methods and camera usage

 

I:

For more information, see www.bkjia.com.

The following describes how to use Quartz 2D drawing to implement the graphic board function.

In the. m file, dog is implemented as shown in the connection.

 

 
# Import drawTestView. h # import Dog. h @ implementation drawTestView @ synthesize dogs, tempdogs;-(NSMutableArray *) dogs {if (dogs = nil) {dogs = [NSMutableArray array];} return dogs ;} -(NSMutableArray *) tempdogs {if (tempdogs = nil) {tempdogs = [NSMutableArray array];} return tempdogs;}-(void) drawRect :( CGRect) rect {CGContextRef ctx = UIGraphicsGetCurrentContext (); CGContextSetFillColorWithColor (ctx, [[UIColor greenColor] CGColor]); // graphic board function [dogs Background: ^ (id obj, NSUInteger idx, BOOL * stop) {NSMutableArray * arr = [dogs objectAtIndex: idx]; for (int I = 0; I <[arr count]; I ++) {Dog * dog = (Dog *) [arr objectAtIndex: I]; if (I = 0) {CGContextMoveToPoint (ctx, dog. x, dog. y);} else {CGContextAddLineToPoint (ctx, dog. x, dog. y) ;}}]; [[UIColor blackColor] setStroke]; CGContextDrawPath (ctx, kCGPathStroke);}-(void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {UITouch * touch = [touches anyObject]; CGPoint location = [touch locationInView: self]; Dog * dog = [[Dog alloc] init]; dog. x = location. x; dog. y = location. y; [self. tempdogs addObject: dog]; [self. dogs addObject: self. tempdogs]; [self setNeedsDisplay]; // call the draw method}-(void) touchesMoved :( NSSet *) touches withEvent :( UIEvent *) event {UITouch * touch = [touches anyObject]; CGPoint location = [touch locationInView: self]; Dog * dog = [[Dog alloc] init]; dog. x = location. x; dog. y = location. y; [self. tempdogs addObject: dog]; [self. dogs addObject: [self. tempdogs copy]; [self setNeedsDisplay]; // call the draw method}-(void) touchesEnded :( NSSet *) touches withEvent :( UIEvent *) event {[tempdogs removeAllObjects];}


Ii. Use of cameras 

 

To be implemented in the viewcontroller in use

// If you write only one UIImagePickerControllerDelegate, a warning is reported, or even the proxy method is not called.

 

    imagePicker = [[UIImagePickerController alloc]init];    imagePicker.delegate = self;


 

How to enter the camera

 

 

-(IBAction) goImagePicker :( id) sender {if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {self. imagePicker. sourceType = UIImagePickerControllerSourceTypeCamera; self. imagePicker. cameraDevice = UIImagePickerControllerCameraDeviceFront; // call the front image header} else {self. imagePicker. sourceType = UIImagePickerControllerSourceTypePhotoLibrary;} self. imagePicker. allowsEditing = YES; [self presentViewController: self. imagePicker animated: YES completion: nil];}


 


 

Implement two proxy methods:

 

-(Void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary *) info {NSLog (@ select); UIImage * image = [info objectForKey: alias]; _ imageSelect. frame = CGRectMake (_ imageSelect. frame. origin. x, _ imageSelect. frame. origin. y, _ imageSelect. frame. size. width, _ imageSelect. frame. size. width * image. size. height/image. size. width); // to Prevent Deformation of the selected image _ imageSelect. image = image; [self. imagePicker dismissViewControllerAnimated: YES completion: nil];}-(void) imagePickerControllerDidCancel :( UIImagePickerController *) picker {[self. imagePicker dismissViewControllerAnimated: YES completion: nil];}


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.