2015-09-08 13 views
7

既然Instagram應用程序可以處理和張貼該應用程序內的非正方形圖像,我希望我可以使用相同的應用程序從我的應用程序發送非方形圖像到Instagram應用程序提供iPhone掛鉤我一直在使用(https://instagram.com/developer/iphone-hooks/?hl=en)。但是,它似乎仍然會將我的圖像裁剪成方形,而不是讓我選擇將它們展開爲非方形大小(與我在Instagram應用程序中直接從圖庫中加載非方形照片並且它可以讓我將其展開爲非方形原始尺寸)。任何人都有幸發送非方形圖像?我希望有一些調整,將使其工作。Instagram的iOS與非正方形圖像掛鉤

+0

我也在找這個。你測試了不同的比例嗎?它似乎在Instagram應用程序內,它裁剪了一些肖像圖片,所以也許我們必須找到正確的矩形進行裁剪? –

+0

有趣的是,instagram應用程序本身似乎不允許你採取風景或肖像圖像。它從圖書館導入的唯一圖像允許這樣做。看起來這個新的「功能」只有一半。 – AndyRyan

回答

0

我也希望他們可以在更新時使用非方形照片,但是您仍舊使用舊的方式發佈非方形照片......將它們遮住,以便與白色相符。

https://github.com/ShareKit/ShareKit/blob/master/Classes/ShareKit/Sharers/Services/Instagram/SHKInstagram.m

- (UIImage *)imageByScalingImage:(UIImage*)image proportionallyToSize:(CGSize)targetSize { 

UIImage *sourceImage = image; 
UIImage *newImage = nil; 

CGSize imageSize = sourceImage.size; 
CGFloat width = imageSize.width; 
CGFloat height = imageSize.height; 

CGFloat targetWidth = targetSize.width; 
CGFloat targetHeight = targetSize.height; 

CGFloat scaleFactor = 0.0; 
CGFloat scaledWidth = targetWidth; 
CGFloat scaledHeight = targetHeight; 

CGPoint thumbnailPoint = CGPointMake(0.0,0.0); 

if (CGSizeEqualToSize(imageSize, targetSize) == NO) { 

    CGFloat widthFactor = targetWidth/width; 
    CGFloat heightFactor = targetHeight/height; 

    if (widthFactor < heightFactor) 
     scaleFactor = widthFactor; 
    else 
     scaleFactor = heightFactor; 

    scaledWidth = width * scaleFactor; 
    scaledHeight = height * scaleFactor; 

    // center the image 

    if (widthFactor < heightFactor) { 
     thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5; 
    } else if (widthFactor > heightFactor) { 
     thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5; 
    } 
} 


// this is actually the interesting part: 

UIGraphicsBeginImageContext(targetSize); 

[(UIColor*)SHKCONFIG(instagramLetterBoxColor) set]; 
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0,0,targetSize.width,targetSize.height)); 

CGRect thumbnailRect = CGRectZero; 
thumbnailRect.origin = thumbnailPoint; 
thumbnailRect.size.width = scaledWidth; 
thumbnailRect.size.height = scaledHeight; 

[sourceImage drawInRect:thumbnailRect]; 

newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

if(newImage == nil) NSLog(@"could not scale image"); 

return newImage ; 

}

+0

我建議舉報一個bug,我做了;) – troppoli