将NSData添加到NSData字节数组

时间:2015-05-11 08:18:01

标签: ios objective-c

我想将图像添加到字节数组中。以下代码给出了一个错误。我想我还没有正确完成。

错误

Field has incomplete type 'NSData *__strong[]'

.m档案

@interface MyViewController() {

    NSData *byteArray[];

}
方法内的

NSData *imgD = UIImageJPEGRepresentation(img1, 0.1);

NSData *imgD2 = UIImageJPEGRepresentation(img2, 0.1);        

NSData *imgD3 = UIImageJPEGRepresentation(img13, 0.1);

 [byteArray addObject:imgD];

 [byteArray addObject:imgD2];

 [byteArray addObject:imgD3];

1 个答案:

答案 0 :(得分:1)

You can add an image to an array. Use NSMutableArray instead of NSData*[]. 

.m档案

@interface MyViewController() {    
    NSMutableArray *byteArray;    
}
方法内的

byteArray = [[NSMutableArray alloc] init];   
NSData *imgD = UIImageJPEGRepresentation(img1, 0.1);    
NSData *imgD2 = UIImageJPEGRepresentation(img2, 0.1);            
NSData *imgD3 = UIImageJPEGRepresentation(img13, 0.1);

[byteArray addObject:imgD]; 
[byteArray addObject:imgD2];
[byteArray addObject:imgD3];