iOS next day multi-threaded-03 pairs of column combinations and pictures

Source: Internet
Author: User

*********

//2D Drawing quartz2d//merged image--Watermark- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event{    //1. Queue Groupsdispatch_group_t Group =dispatch_group_create (); dispatch_queue_t Queue= Dispatch_get_global_queue (Dispatch_queue_priority_default,0); //2. Download Picture 1__block UIImage *image1 =Nil; Dispatch_group_async (group, queue,^{Nsurl*URL1 = [Nsurl urlwithstring:@"http://g.hiphotos.baidu.com/image/pic/item/f2deb48f8c5494ee460de6182ff5e0fe99257e80.jpg"]; NSData*data1 =[NSData DATAWITHCONTENTSOFURL:URL1]; Image1=[UIImage imagewithdata:data1];        }); //3. Download Picture 2__block UIImage *image2 =Nil; Dispatch_group_async (group, queue,^{Nsurl*URL2 = [Nsurl urlwithstring:@"Http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png"]; NSData*DATA2 =[NSData Datawithcontentsofurl:url2]; Image2=[UIImage Imagewithdata:data2];        }); //4. Merge pictures (ensure that all tasks within the group are executed, and then execute the block inside the Notify function)Dispatch_group_notify (group, queue, ^{        //To open a bitmap contextUigraphicsbeginimagecontextwithoptions (Image1.size, NO,0.0); //draw the 1th pictureCGFloat image1w =Image1.size.width; CGFloat image1h=Image1.size.height; [Image1 Drawinrect:cgrectmake (0,0, IMAGE1W, image1h)]; //draw the 2nd pictureCGFloat image2w = Image2.size.width *0.5; CGFloat image2h= Image2.size.height *0.5; CGFloat image2y= image1h-image2h; [Image2 Drawinrect:cgrectmake (0, image2y, image2w, image2h)]; //get the picture in contextUIImage *fullimage =Uigraphicsgetimagefromcurrentimagecontext (); //End ContextUigraphicsendimagecontext (); //5. Go back to the main thread to display the pictureDispatch_async (Dispatch_get_main_queue (), ^{self.imageView.image=Fullimage;    }); });}

iOS next day multi-threaded-03 pairs of column combinations and pictures

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.