1.繼承鏈:NSObject
2.以下有三種方法來創建圖片對象
(1) imageNamed:inBundle:compatibleWithTraitCollection:從image asset或者主要的捆綁包中載入圖片來進行創建圖片對象。
(2) imageWithContentsOfFile:
or initWithContentsOfFile:從本地文件中載入圖片進行創建圖片對象
(3) animatedImageWithImages:duration:
and animatedImageNamed:duration:可以創建一個包含多個圖片的圖片對象,一般是用來播放動畫的
3.使用 UIImagePickerController可以讓用戶進入自己的相冊選取照片
4. 使用resizableImageWithCapInsets:
or resizableImageWithCapInsets:resizingMode:方法可以定義可伸展圖片,可以改變圖片的大小以適合容器的大小,讓人看起來更加舒服
5.使用isequal方法可以判斷兩張圖片是否相等,這是唯一的方法,使用==是錯誤的
UIImage* image1 = [UIImage imageNamed:@"MyImage"];
UIImage* image2 = [UIImage imageNamed:@"MyImage"];
// The image objects may be different, but the contents are still equal
if ([image1 isEqual:image2]) {
// Correct. This technique compares the image data correctly.
}
6. 可以使用CGImage
and CIImage屬性來檢索各種版本的圖片
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. |
rect 在當前的上下文中重新繪制整個圖片的大小
rect
blendMode:(CGBlendMode)blendMode
alpha:(CGFloat)alpha 在當前的上下文中重新繪制圖片的大小、模式和透明度
rect 在指定的矩形中使用Quartz pattern來拼湊圖片
UIImageRenderingMode:UIImageRenderingModeAutomatic, UIImageRenderingModeAlwaysOriginal, UIImageRenderingModeAlwaysTemplate,