ios - Creating GIF from UIImages with CGImageDestinationRef results in broken line at bottom -
my code try creating gif images:
+ (nsdata *)creategifdatawithimages:(nsarray *)images duration:(cgfloat)duration withfilename:(nsstring *)filename { cgfloat durationpadding = duration/((cgfloat)images.count); nsstring *path = [[nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) lastobject] stringbyappendingpathcomponent:filename]; cgimagedestinationref destination = cgimagedestinationcreatewithurl((cfurlref)[nsurl fileurlwithpath:path], kuttypegif, images.count, null); nsdictionary *frameproperties = [nsdictionary dictionarywithobject:[nsdictionary dictionarywithobject:@(durationpadding) forkey:(nsstring *)kcgimagepropertygifdelaytime] forkey:(nsstring *)kcgimagepropertygifdictionary]; nsdictionary *gifproperties = [nsdictionary dictionarywithobject:[nsdictionary dictionarywithobject:[nsnumber numberwithint:0] forkey:(nsstring *)kcgimagepropertygifloopcount] forkey:(nsstring *)kcgimagepropertygifdictionary]; [images enumerateobjectsusingblock:^(id _nonnull obj, nsuinteger idx, bool * _nonnull stop) { uiimage *image = (uiimage *)obj; cgimagedestinationaddimage(destination, image.cgimage, (cfdictionaryref)frameproperties); }]; cgimagedestinationsetproperties(destination, (cfdictionaryref)gifproperties); cgimagedestinationfinalize(destination); cfrelease(destination); nslog(@"animated gif file created @ %@", path); return [nsdata datawithcontentsoffile:path]; }
it did create gif @ last, image looks this:
aha,i fix bug
i thing images create or modification
uigraphicsbeginimagecontextwithoptions(size, opaque, scale);
just set opaque no ! enjoy yourself
Comments
Post a Comment