Image mosaic for IOS

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size: 18px;">/**</span></p></p><p><p><span style="font-size: 18px;">* Achieve mosaic effect</span></p></p><p><p><span style="font-size: 18px;">*/</span></p></p><p><p><span style="font-size: 18px;">Export Ciimage Pictures</span></p></p><p><p><span style="font-size: 18px;">Ciimage *ciimage = [[ciimage alloc] initwithimage:[uiimageimagenamed:@ "de.png"];</span></p></p><p><p><span style="font-size: 18px;"></span></p></p><p><p><span style="font-size: 18px;">1. Create a filter filter</span></p></p><p><p><span style="font-size: 18px;">Cifilter *filter = [cifilter filterwithname:@ "cipixellate"];</span></p></p><p><p><span style="font-size: 18px;">[filter Setvalue:ciimage forkey:kciinputimagekey];</span></p></p><p><p><span style="font-size: 18px;">[filter setdefaults];</span></p></p><p><p><span style="font-size: 18px;">Ciimage *outimage = [filter valueforkey:kcioutputimagekey];</span></p></p><p><p><span style="font-size: 18px;"></span></p></p><p><p><span style="font-size: 18px;">2. Use Cicontext to render the images in the filter</span></p></p><p><p><span style="font-size: 18px;">Cicontext *context = [cicontext contextwithoptions:nil];</span></p></p><p><p><span style="font-size: 18px;">Cgimageref cgimage = [context createcgimage:outimage fromrect:[outimage extent];</span></p></p><p><p><span style="font-size: 18px;"></span></p></p><p><p><span style="font-size: 18px;">3. Export pictures</span></p></p><p><p><span style="font-size: 18px;">UIImage *showimage = [UIImage imagewithcgimage:cgimage];</span></p></p><p><p><span style="font-size: 18px;">Cgimagerelease (cgimage);</span></p></p><p><p><span style="font-size: 18px;"></span></p></p><p><p><span style="font-size: 18px;">4. Load it out</span></p></p><p><p><span style="font-size: 18px;">Uiimageview *imageview = [[uiimageview alloc] initwithimage:showimage];</span></p></p><p><p><span style="font-size: 18px;">Imageview.center = self.window.center;</span></p></p><p><p><span style="font-size: 18px;">[self.window addsubview:imageview];</span></p></p><p><p>Image mosaic for IOS</p></p></span>
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.