大图片分段发送 iphone

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#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];

你可能感兴趣的:(iPhone)