第51月第8天 nsdata分割
1.
#define A_RECEIVE 1000 NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"xxx.jpg"], 1); NSMutableArray *imageDataArray = [[NSMutableArray alloc] init]; for (int i = 0; i<= [imageData length]-A_RECEIVE; i+=A_RECEIVE) { lastIValue = i+A_RECEIVE; NSString *rangeStr = [NSString stringWithFormat:@"%i,%i",i,A_RECEIVE]; NSData *subData = [imageData subdataWithRange:NSRangeFromString(rangeStr)]; [imageDataArray addObject:subData]; } NSString *rangeStr = [NSString stringWithFormat:@"%i,%i",lastIValue,[imageData length]%A_RECEIVE]; NSData *subData = [imageData subdataWithRange:NSRangeFromString(rangeStr)]; [imageDataArray addObject:subData]; NSMutableData *newData = [[NSMutableData alloc] init]; for (int i = 0; i< [imageDataArray count]; i++) { [newData appendData:[imageDataArray objectAtIndex:i]]; } [imageDataArray release]; UIImage *newImage = [[UIImage alloc] initWithData:newData]; [newData release]; [testImage setImage:newImage]; [newImage release];
https://www.cnblogs.com/zhwl/archive/2013/01/05/2845183.html