After one months of laziness, write a question about the project today.
Picture A and Picture B overlay each other, a picture is surrounded by a white irregular shape, filled with black. b picture is a normal picture.
The requirements are superimposed together, requiring the B image to be deducted from the black shape of the a image.
Figure A: Figure B:
Buckle out of:
On the code:
-(uiimage*) Maskimage: (UIImage *) image withmask: (UIImage *) maskimage {cgimageref maskref=Maskimage.cgimage; Cgimageref Mask=cgimagemaskcreate (Cgimagegetwidth (Maskref), Cgimagegetheight (Maskref), Cgimagegetbitspercomponent (maskref), cgimagegetbits Perpixel (Maskref), Cgimagegetbytesperrow (Maskref), Cgimagegetdataprovider (Maskref), NULL,false); Cgimageref Sourceimage=[Image Cgimage]; Cgimageref Imagewithalpha=Sourceimage; //Add alpha channel for images that don't have one (ie GIF, JPEG, etc ...) //This however have a computational cost if(Cgimagegetalphainfo (sourceimage) = =Kcgimagealphanone) {//imagewithalpha =copyimageandaddalphachannel (sourceimage);} cgimageref Masked=Cgimagecreatewithmask (Imagewithalpha, mask); Cgimagerelease (mask); if(Sourceimage! =Imagewithalpha) {cgimagerelease (Imagewithalpha); } UIImage* Retimage =[UIImage imagewithcgimage:masked]; Cgimagerelease (masked); returnretimage;}
GitHub Address: https://github.com/zhuxinleibandou/-
IOS Mask, picture overlay shows empty part