【问题标题】:Instagram iOS hooks with non-square imagesInstagram iOS 钩子与非方形图像
【发布时间】:2015-09-08 18:21:42
【问题描述】:

现在 Instagram 应用程序可以处理和发布该应用程序中的非方形图像,我希望我可以使用我一直使用的相同 iPhone 挂钩从我的应用程序将非方形图像发送到 Instagram 应用程序(https://instagram.com/developer/iphone-hooks/?hl=en)。但是,它似乎仍然将我的图像裁剪为正方形,并且没有让我选择将它们扩展为非正方形大小(与我直接从 Instagram 应用程序中的库加载非正方形照片不同,它让我将其扩展为非方形的原始尺寸)。任何人都有运气发送非方形图像?我希望有一些调整可以让它发挥作用。

【问题讨论】:

  • 我也在找这个。你测试过不同的比例吗?似乎在 Instagram 应用程序内部,它裁剪了一些人像图片,所以也许我们必须找到合适的矩形来裁剪?
  • 有趣的是,Instagram 应用程序本身似乎也不允许您拍​​摄横向或纵向图像。它唯一从库中导入的图像允许这样做。看来这个新的“功能”只是半生不熟。

标签: ios instagram


【解决方案1】:

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

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 ;

}

【讨论】:

  • 我建议报告一个错误,我做到了;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-05-12
  • 1970-01-01
  • 2015-05-16
  • 2017-03-13
  • 2016-02-09
  • 2012-10-25
  • 1970-01-01
相关资源
最近更新 更多