现在Instagram应用程序可以处理和发布该应用程序内的非方形图像,我希望我可以使用我一直使用的相同提供的iPhone挂钩从我的应用程序向Instagram应用程序发送非方形图像(https: //instagram.com/developer/iphone-hooks/?hl=en).然而,它仍然似乎是将我的图像裁剪成方形,而不是让我选择将它们扩展到非方形尺寸(不像我从Instagram应用程序直接在图库中加载非方形照片时它让我将其扩展到非方形原始尺寸).任何人都有运气发送非方形图像?我希望有一些调整可以使它工作.
小智 0
我也希望他们能在更新时拍摄非方形照片,但您仍坚持使用发布非方形照片的旧解决方案......将它们磨砂为白色方形。
- (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 ;
Run Code Online (Sandbox Code Playgroud)
}
归档时间: |
|
查看次数: |
280 次 |
最近记录: |