gpt4 book ai didi

ios - Instagram iOS Hook 与非方形图像

转载 作者:可可西里 更新时间:2023-11-01 03:34:57 26 4
gpt4 key购买 nike

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

最佳答案

我也希望他们能通过更新拍摄非方形照片,但您仍然坚持发布非方形照片的旧解决方案....用白色将它们 mask 成方形。

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com