新分配的指针,移动前先保存 首地址,不然移动的最后,free(*p)会指错
-(NSData*)getImageData{
UIImage *img = [UIImage imageNamed:@"img1_8"];
CGImageRef imgRef =img.CGImage;
NSData *data2 = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"img1_8" ofType:@"png"]];
Byte *buf = calloc(1, data2.length);
NSLog(@"%lu",sizeof(data2));
[data2 getBytes:buf length:data2.length];
Byte *buf1= buf;
for (int i= 0 ; i<data2.length; ++i) {
NSLog(@"%d=>[%x] ",i,*(buf++));
}
@try
{
}
@catch(NSException * e) {
}
NSData*data = [NSData dataWithBytes:buf length:data2.length];
free(buf1);
return data;
}
时间: 2024-10-24 16:15:35