Instagram iOS挂钩与非方形图像

前端之家收集整理的这篇文章主要介绍了Instagram iOS挂钩与非方形图像前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
现在Instagram应用程序可以处理和发布该应用程序内的非方形图像,我希望我可以使用我一直在使用的相同提供的iPhone挂钩从我的应用程序向Instagram应用程序发送非方形图像( https://instagram.com/developer/iphone-hooks/?hl=en) .然而,它仍然似乎是将我的图像裁剪成方形,而不是让我选择将它们扩展到非方形尺寸(不像我从Instagram应用程序直接在图库中加载非方形照片时它让我将其扩展到非方形原始尺寸).任何人都有运气发送非方形图像?我希望有一些调整可以使它工作.

解决方法

我也希望他们会在更新时拍摄非方形照片,但你仍然坚持使用旧的解决方案发布非方形照片……将它们变成白色方形.

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,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 ;

}

猜你在找的iOS相关文章