2013-12-20 38 views
1

我在做iPhone應用程序。在那我將圖像轉換成base64字符串。但是,我的問題是在轉換爲base64字符串之前,我想驗證圖像大小,如果下面的圖像大小250x250,我想把alertview否則如果imaage包含超過250x250或相同大小的euqal那麼只有我需要發送圖像爲base64字符串到服務器。 plase給我你的寶貴建議。先謝謝了!即時通訊做下面的代碼如何驗證iPhone中的圖像?

for(int img_pos=0;img_pos<[uploadPhotosArray count];img_pos++) 
{ 
    [self startIndicator]; 
    conversionImage= [UIImage imageWithContentsOfFile:[uploadPhotosArray objectAtIndex:img_pos]]; 
    NSData *imageData = UIImageJPEGRepresentation(conversionImage,1.0); 
    [Base64 initialize]; 
    NSString *uploadPhotoEncodedString = [Base64 encode:imageData]; 
    //NSLog(@"Byte Array %d : %@",img_pos,uploadPhotoEncodedString); 
    [uploadPhotosByteArray addObject:uploadPhotoEncodedString]; 

} 

回答

1

簡單的檢查了

if(image.size.height>=250&&image.size.width>=250) 
{ 
    NSLog(@"Convert it"); 
} 
else 
{ 
    //alertview 
} 
+0

感謝阿曼AGGARWAL,它非常有用而簡單! –

1

您可以檢查大小屬性,以達致這

CGFloat width = conversionImage.size.width; 
CGFloat height = conversionImage.size.height; 

您可以通過scale屬性找到DPI(分辨率/縮放)。

+0

有用的代碼給我 –