IOS picture file format judgment, fillet picture

Source: Internet
Author: User
Tags webp

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

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.