图像压缩(裁剪)
来源:互联网 发布:知乎 杜嘟嘟 编辑:程序博客网 时间:2024/05/16 10:28
http://blog.csdn.net/pjk1129/article/details/6884774
- (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize
{
UIImage *sourceImage = self;
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; // scale to fit height
else
scaleFactor = heightFactor; // scale to fit width
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;
}
}
UIGraphicsBeginImageContext(targetSize); // this will crop
CGRect thumbnailRect = CGRectZero;
thumbnailRect.origin = thumbnailPoint;
thumbnailRect.size.width= scaledWidth;
thumbnailRect.size.height = scaledHeight;
[sourceImage drawInRect:thumbnailRect];
newImage = UIGraphicsGetImageFromCurrentImageContext();
if(newImage == nil)
NSLog(@"could not scale image");
//pop the context to get back to the default
UIGraphicsEndImageContext();
return newImage;
}
- 图像压缩(裁剪)
- 基于接缝裁剪的图像压缩
- 【开源】canvas图像裁剪、压缩、旋转
- 动态规划之基于接缝裁剪的图像压缩
- 图像裁剪
- 图像裁剪
- 图像裁剪
- python(pil)图像处理(等比例压缩、裁剪压缩) 缩略(水印)图
- Android 图像选取 图片剪裁 照相选图 照相裁剪 图像压缩 11 - 14更新
- 生活编程(二) 图像裁剪批处理
- (2)Java开发图像裁剪系统
- opencv3实现图像裁剪和图像填充(cv::copyMakeBorder)
- Java图片缩略图裁剪水印缩放旋转压缩转格式-Thumbnailator图像处理
- Java图片缩略图裁剪水印缩放旋转压缩转格式-Thumbnailator图像处理
- Java图片缩略图裁剪水印缩放旋转压缩转格式-Thumbnailator图像处理
- Java图片缩略图裁剪水印缩放旋转压缩转格式-Thumbnailator图像处理
- Java图片缩略图裁剪水印缩放旋转压缩转格式-Thumbnailator图像处理
- 算法导论 思考题 15-8(基于接缝裁剪的图像压缩)
- useful Linux command
- poj 2513 -- Colored Sticks ( Trie + 并查集 + 欧拉 )
- jQuery参考实例 1.0 jQuery的哲学
- UILabel的属性和方法
- getch getche getchar的区别
- 图像压缩(裁剪)
- 隔夜利率再现过山车 央行或加码回笼力度
- php获取网页内容方法总结
- SOA-SSH分层架构
- Set Start Transaction after SAP Logon
- SERDES和SGMII
- 端口被禁止无法远程连接Mysql服务器
- Hibernate注解关系映射
- 1403 一个新的取石子游戏