en

hi, it seems you are using microsoft internet explorer. it doesn't match web standard and causes problems browsing this site. please please please use mozilla firefox or google chrome instead. thank you!

zh

哦哦!您正在使用Internet Explorer 瀏覽器,它與我們的網頁標準並不相容,可能會導致畫面顯示不正常。
請改用 Mozilla Firefox 或者 Google Chrome 才能正常瀏覽本網站,謝謝!

11.04.2011

重複影像遮罩的設定方法

  

iOS 5 SDK 替 UIImage 新增了一個可以設定縮放範圍的方法 resizableImageWithCapInsets:,透過這個方法你可以替 UIImage 設定一個重複影像的遮罩,在遮罩內的影像遇到放大時會採用複製的方式來進行繪製,有別於一般的影像放大,使用這種方法可以避免影像的失真。上圖是一張 44 x 44 像素的圖片,並使用不同的設定值在橫向放大上的結果,可以明顯看出它門之間的差異。



上圖(左)我們並沒有對 UIImage 做任何的設定,只是單純將 UIImageView 放大,而 UIImage 也跟著被拉寬。

上圖(中)使用以下的參數做設定,將整個 UIImage 都設保留的範圍(上下左右都為 0),在 UIImageView 放大之後,UIImage 則是做類似自我複製的動作來填滿整個 UIImageView。

UIImage *image = [[UIImage imageNamed:@"demo"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
上圖(右)使用另一種參數來作設定,達到只重複 UIImage 其中一小部份的效果。

UIImage *image = [[UIImage imageNamed:@"demo"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 20)];





沒有留言:

張貼留言