Objective C的圖形類使用基礎課程(四)

騰訊視頻  Objective C的圖形類使用    連接:http://dwz.cn/zH6nM iphone


一.UIImage類是用來處理圖像,好比在窗口上顯示圖像,從一個文件上讀取圖像等等。spa

    1.UIImage提供了一下不一樣的方法來讀取圖片,從而建立圖像對象;orm

       //從應用程序上讀取圖像,參數爲文件名(文件已經拷貝在應用中)視頻

       +【UIImage imageNamed:(NSString *) name】對象

       //從文件系統上讀取圖像,參數爲完整文件名(包括路徑信息)圖片

       -  [UIImage initWithContentsOfFile:(NSString *)path]ip

       -  [UIImage initWithData:(NSData *)data]//從內存中讀取圖像數據內存

         除了讀取圖像外,UIImage還能夠生成一個bitmap圖像。好比,用戶在某一個應用程序的窗口上畫了一個圖,而後 應用程序能夠將該圖保存成一個bitmap圖像。開發

         -(UIImage *)saveToImage:(CGSize)size{get

              UIImage *result=nil;

              UIGraphicsBeginImageContext(size);

             //調用畫圖的代碼

             result=UIGraphicsGetImageFromCurrentContext();//捕捉所化的圖

             UIGraphicsEndImageContext();

            return result; 

 

       } 

      另外,你能夠使用以下方法將圖像轉換成PNG和JPEG

       NSData  *UIImagePNGRepresentation(UIImage *image);

       NSData  *UIImageJPGRepresentation(UIImage *image);

      UIImages也提供了drawRect方法,因此,開發人員能夠調用下述方法畫圖:

  

      -【UIImage drawAtPoint:(CGPoint)point】

      -【UIImage drawAtPoint:(CGPoint)point】

      -【UIImage drawAsPatternInRect :(CGRect)rect】

二.圖像的滾動.放大和縮小

     在建立視圖時,你能夠在界面建立器上設置UIScrollView的大小。

     CGRect  fram =CGRectMake(0,0,200,200);

     scrollView =[[UIScrollView alloc] initWithFrame:frame];

     首先建立圖像視圖,而後添加該圖像視圖到滾動視圖下。最後設置滾動視圖的大小爲圖像視圖的大小:

     frame=CGRectMake(0,0,500,500);

     myImageView=【【UIImageView alloc】initWithFrame:frame】

    【scrollView addSubview:myImageView];

     scollView.contetSize=CGSizeMake(500,500);

     在iphone中是經過UIScrollViewDelegate來完成。

     初了滾動,UIScrollView也支持放大和縮小,好比:

      scrollView.maximumZoomScale=2.0;

      scrollView.minimumZoomScale=scrollView.size.width/myImage.size.width;

相關文章
相關標籤/搜索