该代码应该从选择器视图中选择图像的数据块并将其上传到网站,但每次我尝试上传特定块时,它都会给我一个 EXC_BAD_ACCESS。以下是拆分图像数据的代码大块
PrimaryImageController.h
@interface PrimaryImageViewController
{
__weak IBOutlet UIImageView *imgView;
}
@property (nonatomic,strong) NSMutableArray *chunkArray;
PrimaryImageController.m
@synthesize imgView,chunkArray;
- (void)viewDidLoad
{
chunkArray=[[NSMutableArray alloc]init];
}
-(void)updateImage
{
UIImage *img = imgView.image;
NSData *dataObj=UIImageJPEGRepresentation(img, 1.0);
NSUInteger length = [dataObj length];
NSUInteger chunkSize = 3072*10;
NSUInteger offset = 0;
int numberOfChunks=0;
do
{
NSUInteger thisChunkSize = length - offset > chunkSize ? chunkSize : length - offset;
NSData* chunk = [NSData dataWithBytesNoCopy:(char *)[dataObj bytes] + offset
length:thisChunkSize
freeWhenDone:NO];
offset += thisChunkSize;
[chunkArray insertObject:chunk atIndex:numberOfChunks];
numberOfChunks++;
}
while (offset < length);
for (int i=0; i<[chunkArray count]; i++)
{
[uploadPrimary uploadImage:[chunkArray objectAtIndex:i] uuid:uniqueIdString numberOfChunks:[chunkArray count] currentChunk:i];
}
}