1. Fillet picture
//set up a circular picture (for use in a category)-(UIImage *) cutcircleimage {uigraphicsbeginimagecontextwithoptions (self.size, NO,0.0); //Get ContextCgcontextref CTR =Uigraphicsgetcurrentcontext (); //Set the CircleCGRect rect = CGRectMake (0,0, Self.size.width, self.size.height); Cgcontextaddellipseinrect (CTR, rect); //croppingCgcontextclip (CTR); //draw the picture up[self drawinrect:rect]; UIImage*image =Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); returnimage;}
2. image File Format judgment
//get the picture extension by the first byte of the image data-(NSString *) Contenttypeforimagedata: (NSData *) data {uint8_t C; [Data getBytes:&c Length:1]; Switch(c) { Case 0xFF: return @"JPEG"; Case 0x89: return @"PNG"; Case 0x47: return @"gif"; Case 0x49: Case 0x4d: return @"TIFF"; Case 0x52: if([Data length] < A) { returnNil; } nsstring*teststring = [[NSString alloc] Initwithdata:[data subdatawithrange:nsmakerange (0, A)] [encoding:nsasciistringencoding]; if([TestString Hasprefix:@"RIFF"] && [teststring hassuffix:@"WEBP"]) { return @"WEBP"; } returnNil; } returnNil;} NSString*path =@"Http://xxx.xxx.xxx/xxx.png"; NSData*data =[NSData Datawithcontentsofurl:[nsurl Urlwithstring:path];//calledNSString *string=[self contenttypeforimagedata:data];//the output is PNGNSLog (@"%@",string);
Reference article: HTTP://WWW.JIANSHU.COM/P/8207621DDCAA
IOS picture file format judgment, fillet picture