iOS (Quartz 2D Drawing) Various drawing methods and the use of cameras

Source: Internet
Author: User


One:

Specific use of the details, I also refer to http://blog.163.com/wkyuyang_001/blog/static/10802122820133190545227/

The following describes the use of Quartz 2D drawing to implement the drawing board function

In the. m file, the implementation of the dog is the same as shown in the connection

<pre name= "code" class= "OBJC" > #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]); drawing board features [dogs enumerateobjectsusingblock:^ (id obj, Nsuinteger idx, BOOL *stop) {Nsmutablearray*arr = [dogs objec            TATINDEX: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 draw method}-(void) touchesmoved: (Nsset *) touches withevent: (uievent *) event{Uitouch*tou    CH = [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 draw method}-(void) touchesended: (Nsset *) touches withevent: (uievent *) event{[tempdogs Remov Eallobjects];}


Second: The use of the camera

To implement in the Viewcontroller used

< uinavigationcontrollerdelegate , uiimagepickercontrollerdelegate >//If you write only one uiimagepickercontrollerdelegate, a warning will appear, and you will not even invoke the proxy method

    Imagepicker = [[Uiimagepickercontroller alloc]init];    Imagepicker.delegate = self;


How to get into the camera

-(Ibaction) Goimagepicker: (ID) Sender {        if ([Uiimagepickercontroller issourcetypeavailable: Uiimagepickercontrollersourcetypecamera]) {        Self.imagePicker.sourceType = Uiimagepickercontrollersourcetypecamera;        Self.imagePicker.cameraDevice = uiimagepickercontrollercameradevicefront;//invokes the front-facing 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:uiimagepickercontrollereditedimage];    _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);//In order not to distort the selected picture    _imageselect.image = image;    [Self.imagepicker Dismissviewcontrolleranimated:yes completion:nil];} -(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{    [Self.imagepicker Dismissviewcontrolleranimated:yes Completion:nil];}


iOS (Quartz 2D Drawing) Various drawing methods and the use of cameras

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.