通過(guò)服務(wù)器獲取
后臺(tái)開(kāi)發(fā)人員在返回圖片地址的同時(shí),返回圖片尺寸比例數(shù)據(jù)采记。
利用ImageIO創(chuàng)建CGImageSourceRef對(duì)象
此方法會(huì)下載圖片佣耐,且同步執(zhí)行。
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)[NSURL URLWithString:fileurl], NULL);
CGFloat width = 0, height = 0;
if (imageSource)
{
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
if (imageProperties != NULL)
{
CFNumberRef widthNum = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
if (widthNum != NULL) {
CFNumberGetValue(widthNum, kCFNumberFloat64Type, &width);
}
CFNumberRef heightNum = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
if (heightNum != NULL) {
CFNumberGetValue(heightNum, kCFNumberFloat64Type, &height);
}
CFRelease(imageProperties);
}
CFRelease(imageSource);
}