0

我有两种方法,都给出了错误的答案。

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

4

2 回答 2

0

尝试改变你的

NSData *imgData = UIImageJPEGRepresentation([UIImage imageWithData:myEncodedImageData], 1);

为了

NSData *imgData = [[NSData alloc] initWithData:UIImageJPEGRepresentation((your_ui_image), 0.5)];
于 2013-03-11T08:20:20.280 回答
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;
于 2015-05-21T08:25:25.180 回答