Swift的圖片處理類:Toucan

jopen 9年前發布 | 39K 次閱讀 Toucan Apple Swift開發

Toucan 是一個 Swift 庫,提供整潔,快速的 API 來處理圖片。可以大大簡化圖片的生成,支持縮放,裁剪和美化。

特性

  • 簡單和智能大小調整
  • Elliptical and rounded rect masking
  • Mask with custom images
  • Chainable image processing stages

調整大小

Resize the contained image to the specified size. Depending on whatfitModeis supplied, the image may be clipped, cropped or scaled.

Toucan(image: myImage).resize(size: CGSize, fitMode: Toucan.Resize.FitMode)
or
Toucan.Resize.resizeImage(image: UIImage, size: CGSize, fitMode: FitMode = .Clip) -> UIImage

Fit Mode

FitMode drives the resizing process to determine what to do with an image to make it fit the given size bounds.

Example Mode
Clip Clip Mode
Toucan.Resize.FitMode.Clip
Resizes the image to fit within the width and height boundaries without cropping or distorting the image.

Toucan(image: portraitImage).resize(CGSize(width: 500, height: 500), fitMode: Toucan.Resize.FitMode.Clip).image
Crop Crop Mode
Toucan.Resize.FitMode.Crop
Resizes the image to fill the width and height boundaries and crops any excess image data.

Toucan(image: portraitImage).resize(CGSize(width: 500, height: 500), fitMode: Toucan.Resize.FitMode.Crop).image
Scale Scale Mode
Toucan.Resize.FitMode.Scale
Scales the image to fit the constraining dimensions exactly.

Toucan(image: portraitImage).resize(CGSize(width: 500, height: 500), fitMode: Toucan.Resize.FitMode.Scale).image

Masking

Alter the original image with a mask; supports ellipse, rounded rect and image masks.

Ellipse Mask

Example Function
Ellipse Mask Mask the given image with an ellipse. Allows specifying an additional border to draw on the clipped image. For a circle, ensure the image width and height are equal!

Toucan(image: myImage).maskWithEllipse().image
or
Toucan.Mask.maskImageWithEllipse(myImage) -> UIImage
Ellipse Mask w. Border When specifying a border width, it is draw on the clipped image.

Toucan(image: myImage).maskWithEllipse(borderWidth: 10, borderColor: UIColor.yellowColor()).image
or
Toucan.Mask.maskImageWithEllipse(myImage, borderWidth: 10, borderColor: UIColor.yellowColor()) -> UIImage

Rounded Rect Mask

Example Function
Rounded Rect Mask Mask the given image with a rounded rectangle border. Allows specifying an additional border to draw on the clipped image.

Toucan(image: myImage).maskWithRoundedRect(cornerRadius: 30).image
or
Toucan.Mask.maskImageWithRoundedRect(myImage, cornerRadius: 30) -> UIImage
Rounded Rect Mask w. Border When specifying a border width, it is draw on the clipped rounded rect.

Toucan(image: myImage).maskWithRoundedRect(cornerRadius: 30, borderWidth: 10, borderColor: UIColor.purpleColor()).image
or
Toucan.Mask.maskImageWithRoundedRect(myImage, cornerRadius: 30, borderWidth: 10, borderColor: UIColor.purpleColor()) -> UIImage

Image Mask

Example Function
Image Mask Mask the given image with another image mask. Note that the areas in the original image that correspond to the black areas of the mask show through in the resulting image. The areas that correspond to the white areas of the mask aren’t painted. The areas that correspond to the gray areas in the mask are painted using an intermediate alpha value that’s equal to 1 minus the image mask sample value.

Toucan(image: myImage).maskWithImage(maskImage: octagonMask).image
or
Toucan.Mask.maskImageWithImage(myImage, maskImage: octagonMask) -> UIImage


項目主頁:http://www.baiduhome.net/lib/view/home/1423039476389

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!