图片处理
来源:互联网 发布:软件测试兼职网站 编辑:程序博客网 时间:2024/05/21 05:19
关于图片适应情况的处理
1、使用uiview 属性
contentMode
凡是没有带Scale的,当图片尺寸超过 ImageView尺寸时,只有部分显示在ImageView中。UIViewContentModeScaleToFill属性会导致图片变形。UIViewContentModeScaleAspectFit会保证图片比例不变,而且全部显示在ImageView中,这意味着ImageView会有部分空白。UIViewContentModeScaleAspectFill也会证图片比例不变,但是是填充整个ImageView的,可能只有部分图片显示出来。
官方解释:
内容模式设置啦当view的大小变化的时候,view包含的位图图片如何自动适应。这个属性经常用来重新设置,通常和contentStretch 一起设置。代替每次都要重绘视图。
The content mode specifies how the cached bitmap of the view’s layer is adjusted when the view’s bounds change. This property is often used to implement resizable controls, usually in conjunction with the contentStretch property. Instead of redrawing the contents of the view every time, you can use this property to specify that you want to scale the contents (either with or without distortion) or pin them to a particular spot on the view.
2、使用uiimage方法
- - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode NS_AVAILABLE_IOS(6_0); // the interior is resized according to the resizingMode
3、对UIimage进行绘图处理
+(UIImage *)imageByScalingToSize:(CGSize)targetSize image:(UIImage *)image
{
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);
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 ;
}
- 图片处理
- 处理图片
- 图片处理
- 图片处理
- 图片处理
- 图片处理
- 图片处理
- 图片处理
- 处理图片
- 图片处理
- 图片处理
- 图片处理
- 图片处理
- 图片处理
- 图片处理
- 图片处理
- 图片处理
- 图片处理
- 最简单的基于FFmpeg的解码器-纯净版(不包含libavformat)
- Android Service两种启动启动方式 及 adndroid service生命周期
- 我对Struts2的配置结果的理解
- (五十六)iOS多线程之NSOperation
- 在matlab中显示中文
- 图片处理
- 关于Controller中的重定向做法
- 20条Linux命令面试问答
- SpringMVC路径映射的四种做法
- 测试方法总结
- centos6.5下安装jdk
- HBase入门篇
- WOJ-Problem 1011 - Finding Teammates
- CentOS6.5_7常用命令