uiimagejpegrepresentation的选举差额比例怎么算选

&&当前位置: && && 列表
IOS UIImage类方法总结
来源:网络 && 编辑:admin
IOS中对图片的处理
相信做项目时肯定会有用到 UIImage 这个类,那我们就来看一下这个类中都有什么内容。
其实这篇文章就是在看文档的时候想记录一下文档中得方法。
继承于NSObject
下面介绍一下UIImage中的方法
首先是我们最常用的
通过图片的文件名来获取这个图片
+ (UIImage *)imageNamed:(NSString *)name
//要注意的是这个方法适用于已经导入到工程中的图片
创建新图片
1、+ (UIImage *)imageWithContentsOfFile:(NSString *)path
//通过文件加载指定路径下的文件内容获得新图片
2、+ (UIImage *)imageWithData:(NSData *)data
//通过一个NSData对象来获得图片
3、+ (UIImage *)imageWithData:(NSData *)data scale:(CGFloat)scale
//同上,只是再加上一个图片大小比例,用来改变图片的大小
4、+ (UIImage *)imageWithCGImage:(CGImageRef)cgImage
//使用Quartz 2D对象创建UIImage
5、+ (UIImage *)imageWithCGImage:(CGImageRef)imageRef scale:(CGFloat)scale orientation:(UIImageOrientation)orientation
//制定图片的比例和方向,其中方向是个枚举类。
6、+ (UIImage *)imageWithCIImage:(CIImage *)ciImage
//用一个Core Image 对象创建图像
7、+ (UIImage *)imageWithCIImage:(CIImage *)ciImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation
//再加上比例和图片方向
8、- (UIImage *)imageWithAlignmentRectInsets:(UIEdgeInsets)alignmentInsets
//返回指定矩形区域内的图像
9、+ (UIImage *)animatedImageNamed:(NSString *)name duration:(NSTimeInterval)duration
//创建一个动态图片,动态图片持续的时间为duration
10、+ (UIImage *)animatedImageWithImages:(NSArray *)images duration:(NSTimeInterval)duration
//用一组图片创建一个动态图片,动态持续时间duration
11、+ (UIImage *)animatedResizableImageNamed:(NSString *)name capInsets:(UIEdgeInsets)capInsets duration:(NSTimeInterval)duration
//创建一个在可变大小的图片上指定矩形区域内的动态图片
12、+ (UIImage *)animatedResizableImageNamed:(NSString *)name capInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode duration:(NSTimeInterval)duration
//同上,只是多了一个图片变化的方式,具体来说就是平铺或者拉伸
13、- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
//用制定矩形区域创建图像
14、- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode
//同上,指定图片变化方式
初始化图片
方法的作用在从上面的一些方法中都能找到原型,这里就不一一注释了
1、& initWithContentsOfFile:
//从文件加载图片
2、& initWithData:
//用NSData对象初始化图片
3、& initWithData:scale:
//用NSData对象,指定的比例,初始化图片
4、& initWithCGImage:
5、& initWithCGImage:scale:orientation:
6、& initWithCIImage:
7、& initWithCIImage:scale:orientation:
1、& drawAtPoint:
//在指定的点开始绘画图片,这个点就是图片的做上角顶点
2、- (void)drawAtPoint:(CGPoint)point blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha
//在指定的点绘制整个图片,并使用自定义图片复合模式,并设置透明度
3、& drawInRect:
//在指定区域内绘制图片,可根据需要缩放图片
4、& drawInRect:blendMode:alpha:
//参照上面第二条
5、& drawAsPatternInRect:
//在指定区域内,平铺图片
image的属性
imageOrientation
//图片的方向
//图片的大小size
//图片的比例
resizingMode
//图片变化方式
//潜在的Quartz image
//潜在的Core Image
//返回一个由图片组成的数组,针对于由一组图片生成的动态图片
//返回动态图片持续的时间(即动态图片播放一遍的时间)
//图片上选定的区域
alignmentRectInsets
//图片平铺的区域
iOS自带的提供了一个API如下
[html] view plaincopy
NSData *UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality);
在Iphone上有两种读取图片数据的简单方法: UIImageJPEGRepresentation和UIImagePNGRepresentation. UIImageJPEGRepresentation函数需要两个参数:图片的引用和压缩系数.而UIImagePNGRepresentation只需要图片引用作为参数.通过在实际使用过程中,比较发现: UIImagePNGRepresentation(UIImage* image) 要比UIImageJPEGRepresentation(UIImage* image, 1.0) 返回的图片数据量大很多.譬如,同样是读取摄像头拍摄的同样景色的照片, UIImagePNGRepresentation()返回的数据量大小为199K ,而 UIImageJPEGRepresentation(UIImage* image, 1.0)返回的数据量大小只为140KB,比前者少了50多KB.如果对图片的清晰度要求不高,还可以通过设置 UIImageJPEGRepresentation函数的第二个参数,大幅度降低图片数据量.譬如,刚才拍摄的图片, 通过调用UIImageJPEGRepresentation(UIImage* image, 1.0)读取数据时,返回的数据大小为140KB,但更改压缩系数后,通过调用UIImageJPEGRepresentation(UIImage* image, 0.5)读取数据时,返回的数据大小只有11KB多,大大压缩了图片的数据量 ,而且从视角角度看,图片的质量并没有明显的降低.因此,在读取图片数据内容时,建议优先使用UIImageJPEGRepresentation,并可根据自己的实际使用场景,设置压缩系数,进一步降低图片数据量大小。
[html] view plaincopy
UIImage *imageNew = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
imageNew = [self imageWithImage:imageNew scaledToSize:CGSizeMake(100, 100)];
NSData *imageData = UIImageJPEGRepresentation(imageNew, 0.0001);
m_selectImage = [UIImage imageWithData:imageData];
.h具体code
[html] view plaincopy
#import &Foundation/Foundation.h&
@interface UIImage (UIImageExt)
- (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)
- (UIImage *)imageByScalingAndCroppingForSize:(CGSize)targetS
.m具体code
[html] view plaincopy
#import "UIImageExt.h"
@implementation UIImage (UIImageExt)
- (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
// 创建一个bitmap的context
// 并把它设置成为当前正在使用的context
UIGraphicsBeginImageContext(size);
// 绘制改变大小的图片
[img drawInRect:CGRectMake(0, 0, size.width, size.height)];
// 从当前context中创建一个改变大小后的图片
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
// 使当前的context出堆栈
UIGraphicsEndImageContext();
// 返回新的改变大小后的图片
return scaledI
- (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize
UIImage *sourceImage =
UIImage *newImage =
CGSize imageSize = sourceImage.
CGFloat width = imageSize.
CGFloat height = imageSize.
CGFloat targetWidth = targetSize.
CGFloat targetHeight = targetSize.
CGFloat scaleFactor = 0.0;
CGFloat scaledWidth = targetW
CGFloat scaledHeight = targetH
CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
if (CGSizeEqualToSize(imageSize, targetSize) == NO)
CGFloat widthFactor = targetWidth /
CGFloat heightFactor = targetHeight /
if (widthFactor & heightFactor)
scaleFactor = widthF // scale to fit height
scaleFactor = heightF // scale to fit width
scaledWidth
= width * scaleF
scaledHeight = height * scaleF
// center the image
if (widthFactor & heightFactor)
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
if (widthFactor & heightFactor)
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
UIGraphicsBeginImageContext(targetSize); // this will crop
CGRect thumbnailRect = CGRectZ
thumbnailRect.origin = thumbnailP
thumbnailRect.size.width
thumbnailRect.size.height = scaledH
[sourceImage drawInRect:thumbnailRect];
newImage = UIGraphicsGetImageFromCurrentImageContext();
if(newImage == nil)
NSLog(@"could not scale image");
//pop the context to get back to the default
UIGraphicsEndImageContext();
return newI
来源:网络 && 编辑:admin随笔 - 148&
文章 - 0&评论 - 0&trackbacks - 0
NSData *imageData =&UIImageJPEGRepresentation(self.uploadImage , 0.75);
//图片按0.75的质量压缩-》转换为NSData
NSString *file_name = [TimeUtil&getDateStringWithFormat:@"yyyy-MM-dd-HH-mm-ss"];
//以事件为图片名字
NSString *upload_name =[NSString stringWithFormat:@"%@.jpg",file_name ];
//上传的图片名字
[request&setData:imageData
&&&&withFileName:upload_name
&&andContentType:@"image/jpeg"&
&&&&&&&&&&forKey:@"upload_file"];
UIImageJPEGRepresentation 函数需要两个参数:图片的引用和压缩系数.
而UIImagePNGRepresentation只需要图片引用作为参数.通过在实际使用过程中,
比较发 现:
UIImagePNGRepresentation(UIImage* image) 要比UIImageJPEGRepresentation(UIImage* image, 1.0) 返回的图片数据量大很多.
譬如,同样是读取摄像头拍摄的同样景色的照片
&UIImagePNGRepresentation()返回的数据量大小为199K
&而 UIImageJPEGRepresentation(UIImage* image, 1.0)返回的数据量大小只为140KB
比前者少了50多KB.
如果对图片的清晰度要求不高,还可以通过设置 UIImageJPEGRepresentation函数的第二个参数,大幅度降低图片数据量.
譬如,刚才拍摄的图片, 通过调用UIImageJPEGRepresentation(UIImage* image, 1.0)读取数据时,返回的数据大小为140KB
但更改压缩系数后,通过调用UIImageJPEGRepresentation(UIImage* image, 0.5)读取数据时,返回的数据大小只有11KB多,大大压缩了图片的数据量
&而且从视角角度看,图片的质量并没有明显的降低.因此,在读取图片数据内容时,建议优先使用UIImageJPEGRepresentation,并可 根据自己的实际使用场景,设置压缩系数,进一步降低图片数据量大小
阅读(...) 评论()}

我要回帖

更多关于 获利比例选股的原理 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信