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 ;
}
总结以上是内存溢出为你收集整理的Instagram iOS挂钩与非方形图像全部内容,希望文章能够帮你解决Instagram iOS挂钩与非方形图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)