UIkit框架之UIimage

1.继承链:NSObjecthtml

2.如下有三种方法来建立图片对象api

    (1) imageNamed:inBundle:compatibleWithTraitCollection:从image asset或者主要的捆绑包中载入图片来进行建立图片对象。数组

    (2) imageWithContentsOfFile: or initWithContentsOfFile:从本地文件中载入图片进行建立图片对象app

    (3) animatedImageWithImages:duration: and animatedImageNamed:duration:能够建立一个包含多个图片的图片对象,通常是用来播放动画的
动画

3.使用 UIImagePickerController可让用户进入本身的相册选取照片this

4. 使用resizableImageWithCapInsets: or resizableImageWithCapInsets:resizingMode:方法能够定义可伸展图片,能够改变图片的大小以适合容器的大小,让人看起来更加舒服
spa

image_insets_2x.png

5.使用isequal方法能够判断两张图片是否相等,这是惟一的方法,使用==是错误的code

  1. UIImage* image1 = [UIImage imageNamed:@"MyImage"];
  2. UIImage* image2 = [UIImage imageNamed:@"MyImage"];
  3. // The image objects may be different, but the contents are still equal
  4. if ([image1 isEqual:image2]) {
  5. // Correct. This technique compares the image data correctly.
  6. }

6. 可使用CGImage and CIImage属性来检索各类版本的图片
htm

7.可使用 UIImagePNGRepresentation and UIImageJPEGRepresentation功能来生成png或者JPEG格式的图片数据对象

8.可使用的方法或者属性:

    (1)+ (UIImage *)imageNamed:(NSString *)name

                inBundle:(NSBundle *)bundle
                compatibleWithTraitCollection:(UITraitCollection *)traitCollection,name是在bundle中图片的名称,bundle是用来存储图片的捆绑包,traitcollection暂时还不知道是干吗的,它里面是这样描述的:The traits associated with the intended environment for the image. Use this parameter to ensure that the correct variant of the image is loaded. If you specify nil, this method uses the traits associated with the main screen.

    (2)[image imageWithData:(NSData *)data]经过指定的图片数据对象用来建立和返回一个图片对象

    (3)+ (UIImage *)imageWithData:(NSData *)data
                     scale:(CGFloat)scale   使用这个方法能够经过一个数据对象和比例建立和返回一个图片对象

    (4)+ (UIImage *)imageWithCGImage:(CGImageRef)cgImage   返回一个指定的quartz image对象转变后的对象

    (5)+ (UIImage *)imageWithCGImage:(CGImageRef)imageRef
                        scale:(CGFloat)scale
                  orientation:(UIImageOrientation)orientation    返回一个设定比例和方向的图片对象 ,cgImage是一个quartz image对象

    (6)+ (UIImage *)imageWithCIImage:(CIImage *)ciImage   建立和返回一个core image对象转变后的图片对象  , core image对象是通过压缩封装的图片

    (7)+ (UIImage *)imageWithCIImage:(CIImage *)ciImage
                        scale:(CGFloat)scale
                  orientation:(UIImageOrientation)orientation     返回一个把core image对象的比例和方向转变后的图片对象

    (8)- (instancetype)initWithData:(NSData *)data
                       scale:(CGFloat)scale   返回一个比例为scale且是data里面的图片对象

    (9)+ (UIImage *)animatedImageNamed:(NSString *)name
                       duration:(NSTimeInterval)duration     返回一个动态图片,而且设定了必定的时间

    (10)+ (UIImage *)animatedImageWithImages:(NSArray<UIImage *> *)images
                            duration:(NSTimeInterval)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    返回的对象设定了边界距离属性、内部重构属性(我也不知道这是什么鬼)和动画时间,

                                注意:这个方法通常应用在动画须要改变大小的状况,resizingMode默认的类型是UIImageResizingModeTile,动画改变时使用 UIImageResizingModeStretch属性

    (13)- (UIImage *)imageWithRenderingMode:(UIImageRenderingMode)renderingMode  返回的对象通过renderingmode参数渲染

      (14)- (UIImage *)imageWithAlignmentRectInsets:(UIEdgeInsets)alignmentInsets  返回的对象通过边界距离属性调整,若是你从新调整了按钮的大小,可是北京图片的coners不会改变而且大小会跟随按钮的变化而变化

    (15)- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
                            resizingMode:(UIImageResizingMode)resizingMode    只有当你想使用 UIImageResizingModeStretch方法来重构图片大小的时候你才能够调用这个方法

    (16)- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth
                                 topCapHeight:(NSInteger)topCapHeight        会改变图片里面的中间的区域,大小为leftcapwidth*topcapheight

9.只读属性:size、scale、imageorientation、flipsforrighttoleftlayoutdirection、resizingmode、cgimage、ciimage、images、duration、capinset、alignmentrectinsets、imageasset、traitcollection

10.drawing images

    (1)- (void)drawAtPoint:(CGPoint)point在当前的上下文中绘画图片到指定的点上

    (2)

- (void)drawAtPoint:(CGPoint)point
          blendMode:(CGBlendMode)blendMode
              alpha:(CGFloat)alpha

Parameters

point

The point at which to draw the top-left corner of the image.

blendMode

The blend mode to use when compositing the image.

alpha

The desired opacity of the image, specified as a value between 0.0 and 1.0. A value of 0.0 renders the image totally transparent while 1.0 renders it fully opaque. Values larger than 1.0 are interpreted as 1.0.

   使用某种混合操做和透明度,把图片放在指定的点上
    (3)- ( void)drawInRect:(CGRect)rect   在当前的上下文中从新绘制整个图片的大小
    (4)- (void)drawInRect:(CGRect)rect
         blendMode:(CGBlendMode)blendMode
             alpha:(CGFloat)alpha     在当前的上下文中从新绘制图片的大小、模式和透明度
    (5)- (void)drawAsPatternInRect:(CGRect)rect   在指定的矩形中使用Quartz pattern来拼凑图片
 
 
11.辅助功能
    (1)UIImageOrientation UIImageOrientationUp, UIImageOrientationDown , // 180 deg rotation UIImageOrientationLeft , // 90 deg CW UIImageOrientationRight , // 90 deg CCW UIImageOrientationUpMirrored , // as above but image mirrored along // other axis. horizontal flip UIImageOrientationDownMirrored , // horizontal flip UIImageOrientationLeftMirrored , // vertical flip UIImageOrientationRightMirrored , // vertical flip
    (2)UIImageResizingMode:UIImageResizingModeTile(The image is tiled when it is resized. In other words, the interior region of the original image will be repeated to fill in the interior region of the newly resized image..), UIImageResizingModeStretch
    (3) UIImageRenderingMode:UIImageRenderingModeAutomatic, UIImageRenderingModeAlwaysOriginal, UIImageRenderingModeAlwaysTemplate,
相关文章
相关标签/搜索