Image mosaic for IOS
Last Update:2015-06-19
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>