iphone torn clothes game-image erase

Source: Internet
Author: User

Principle:

The principle of torn clothes game is to use two almost the same photo (two photos of the difference is a more conservative, a more open, in essence, the designer in the original picture of the Open model p on a layer of clothes), the open picture is placed below, Put the conservative picture on top (each picture is placed on a imageview). The process of tearing the garment is the process of erasing the picture, erasing the place where the gesture touches the picture.

Steps:

1. Add pan gestures to the controller and set the Listening method.

2. In the Listening method

2.1 Getting the current point

2.2 Gets the erased rectangle range (centered at the current point, erasing the specified range around the current point)

2.3 Open Context

2.4 Render the layer on the control to the context

2.5 Erasing pictures

2.6. Assign the generated new image to the original ImageView


Code:

-(void) viewdidload {[Super viewdidload]; Adding pan gestures to the controller uipangesturerecognizer *pangesutre = [[Uipangesturerecognizer alloc] initwithtarget:self action: @select        or (pan:)]; [Self.view addgesturerecognizer:pangesutre];} -(void) pan: (Uipangesturerecognizer *) pangesture{//1. Get current point cgpoint currentpoint = [Pangesture locationinview:self.v        Iew];    2. Get the erase rectangle range cgfloat wipewidth = 30;    CGFloat wipeheight = 30;    CGFloat Wipex = currentpoint.x-wipewidth * 0.5;        CGFloat Wipey = currentpoint.y-wipeheight * 0.5;    CGRect rect = CGRectMake (Wipex, Wipey, Wipewidth, wipeheight);    3. Open Context Uigraphicsbeginimagecontextwithoptions (self.view.frame.size, NO, 0);        Cgcontextref CTX = Uigraphicsgetcurrentcontext ();        4. Layer rendering of the control [Self.imageView.layer Renderincontext:ctx];        5. Erase picture Cgcontextclearrect (CTX, rect);    6. Generate a new picture UIImage *image = Uigraphicsgetimagefromcurrentimagecontext (); Self.imageView.image = image;}
Effect Demo:

Picture material sharing: Tearing clothes game picture material


iphone torn clothes game-image erase

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.