3
在這裏,我將我的圖像轉換爲二進制數據的類別在UIImage上有靜態method.My問題是UIImageJPEGRepresentation和UIImagePNGRepresentation是非常緩慢的6秒。我需要1秒的解決方案。任何人都可以幫助我。 在這裏,我將我的圖像傳遞給類別方法,直到它的大小減小到小於或等於10kbs。UIImageJPEGRepresentation和UIImagePNGRepresentation都很慢
-(NSData *)imageConvertToBinary :(UIImage *) image{
NSLog(@"Image Convert ");
//UIImagePNGRepresentation(image);
NSData *imageData = UIImageJPEGRepresentation(image, .000032);
NSLog(@"Image Done ");
//Change size of image to 10kbs
int size = imageData.length;
NSLog(@"SIZE OF IMAGE:First %i ", size);
NSData *data = UIImageJPEGRepresentation(image, .0032);
NSLog(@"Start while ");
int temp=0;
while (data.length/1000 >= 10) {
image = [UIImage imageWithImage:image andWidth:image.size.width/2 andHeight:image.size.height/2];
data = UIImageJPEGRepresentation(image, .0032);
temp++;
NSLog(@"temp %u",temp);
}
size = data.length;
NSLog(@"SIZE OF IMAGE:after %i ", size);
return data;
}
and also i have category class on UIImage
@implementation UIImage (ImageProcessing)
+(UIImage*)imageWithImage:(UIImage*)image andWidth:(CGFloat)width andHeight:(CGFloat)height
{
UIGraphicsBeginImageContext(CGSizeMake(width, height));
[image drawInRect:CGRectMake(0,0,width,height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@end
的NSData *數據; 必須等於什麼
數據代碼尚未初始化 – 2016-02-16 02:57:40