现在,Instagram应用程序可以处理该应用程序中的非方形图像并发布该图像,我希望可以使用与我一直使用的提供的相同iPhone Hook 将非方形图像从我的应用程序发送到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,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 - Instagram iOS与非方形图像 Hook ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32464702/