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,
相關文章
相關標籤/搜索