我是以两种方式做的,两者都给出了错误的答案。
NSMutableArray *img=[[NSMutableArray alloc]init];
img=[memoInstance getTempImagesToSend]; //get nsmutableArray of images
NSData* myEncodedImageData=[img objectAtIndex:0];
NSLog(@"IMAGE1:%@",[UIImage imageWithData:myEncodedImageData]); //i see image
NSLog(@"len:%lu",(unsigned long)[myEncodedImageData length]); //first way to show size
NSData *imgData = UIImageJPEGRepresentation([UIImage imageWithData:myEncodedImageData], 1);
NSLog(@"Size of Image(bytes):%d",[imgData length]); //second way to show
第一种方式:len:34898
Size of Image(bytes):47701
图像来自相册,带着iphone。它不能是47k ......应该像±500k
答案 0 :(得分:0)
尝试更改
NSData *imgData = UIImageJPEGRepresentation([UIImage imageWithData:myEncodedImageData], 1);
的
NSData *imgData = [[NSData alloc] initWithData:UIImageJPEGRepresentation((your_ui_image), 0.5)];
答案 1 :(得分:0)
尝试以下方法:
int height = image.size.height; int width = image.size.width;
int bytesPerRow = 4*width;
if (bytesPerRow % 16)
bytesPerRow = ((bytesPerRow / 16) + 1) * 16;
int dataSize = height*bytesPerRow;