大佬教程收集整理的这篇文章主要介绍了Instagram iOS挂钩与非方形图像,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
- (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挂钩与非方形图像所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。