需要發送一些數據和UIImage到服務器中。
客戶端會返回響應。
但是UIImage發送後客戶端返回的就是這樣:
FaceImage":[255,216,255,224,0,16,74,70,73,70,0,1,1,1,1,44,1,44,0,0,255,219,0,67,0,8,6,6,7,6,5,8,7,7,7,9,9,8,10,12,20,13,12,11,11,12,25,18,19,15,20,29,26,31,30,29,26,28,28,32,36,46,39,32,34,44,35,28,28,40,55,41,44,48,49,52,52,52,31,39,57,61,56,50,60,46,51,52,50,255,219,0,67,1,9,9,9,12,11,12,24,13,13,24,50,.................................................................]
用下面的log測試一下:
NSLog(@"testingImageView.image is =%@",[[[datadic valueForKey:@"FaceImage"] objectAtIndex:0] class]);
回應是 :testingImageView.image is =NSDecimal
如果是NSDate我可以轉換為UIImage,但是這是在十進制格式中。
我想問一下,能不能轉換UIImage?就是講十進制值轉換為UIImage
多謝。
返回的數據已經包含了全部圖片字節。255.216是十六進制的FF.D8,指示一個JPEG圖片的開始。
用下面的代碼轉換吧
NSArray *array = [datadic objectForKey:@"FaceImage"];
NSMutableData *imageData = [NSMutableData dataWithLength:[array count]];
uint8_t *imageBytes = [imageData mutableBytes];
for (NSUInteger i = 0; i < [array count]; i++) {
imageBytes[i] = [array[i] unsignedCharValue];
}
UIImage *image = [UIImage imageWithData:imageData];