3

여기에서 정적 이미지가있는 UIImage에서 카테고리별로 이진 데이터로 이미지를 변환합니다. 내 문제는 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 * 데이터; 는

답변

4

난 당신이

- (NSData *)imageConvertToBinary :(UIImage *) image{ 
    NSData *data ; 
    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); 
    } 
    NSLog(@"End while "); 
    int size = data.length; 
    NSLog(@"SIZE OF IMAGE:after %i ", size); 
    return data; 
} 
+0

데이터를 시도 UIImageJPEGRepresentation 두 배 이상을 사용하고 코드를 줄일 수 뭔가 동일해야합니다 초기화되지 않았습니다 –