UIImage

UIImage

ImageFileType

ประเภทของภาพที่ระบบ Support

enum ImageFileType: String {
    case png = ".png"
    case jpg = ".jpg"
    case gif = ".gif"
    case video = ".video"
    case unknow = ""
}
NameDescription
pngภาพประเภท PNG
jpgภาพประเภท JPEG
gifภาพประเภท GIF
videoวีดีโอ
unknowภาพประเภทอื่นๆ

Method Overview

NameDescriptionReturn
init()การ Initial UIImage ด้วย base64 หรือ URLvoid
jpgData()การแปลงภาพให้เป็น Data ที่เป็นภาพประเภท JPEGOptional(Data)
base64()การแปลงภาพให้เป็น base64Optional(String)
rotate()การหมุนภาพได้แบบอิสระด้วยมุม Radians หรือ DegreeOptional(UIImage)

Method Details

convenience init?(base64: String)

การ Initial UIImage ด้วย base64

Parameters

NameDescriptionType
base64base64 ของภาพที่ต้องการทำมาสร้าง UIImageString
convenience init?(url: URL)

การ Initial UIImage ด้วย URL

Parameters

NameDescriptionType
urlurl ของภาพที่ต้องการทำมาสร้าง UIImageURL
func jpgData(compressionQuality: CGFloat = 0.5) -> Data?

การแปลงภาพให้เป็น Data ที่เป็นภาพประเภท JPEG

Parameters

NameDescriptionType
compressionQualityคุณภาพของภาพที่ต้องการหลังจากทำการ Compress แล้วCGFloat

Returns

TypeDescription
Optional(Data)Return Data ของภาพประเภท JPEG หลังจากทำการ Compress แล้ว
func base64(type: ImageFileType = .png) -> String?

การแปลงภาพให้เป็น base64

Parameters

NameDescriptionType
typeประเภทของภาพที่ต้องการแปลงเป็น base64ImageFileType

Returns

TypeDescription
Optional(String)Return String base64 ของภาพ
func rotate(radians: Float) -> UIImage?

การหมุนภาพได้แบบอิสระด้วยมุม Radians

Parameters

NameDescriptionType
radiansมุมที่ต้องการหมุนภาพFloat

Returns

TypeDescription
Optional(UIImage)Return UIImage ของภาพที่ทำการหมุนแล้ว
func rotate(degree: Float) -> UIImage?

การหมุนภาพได้แบบอิสระด้วยมุม Degree

Parameters

NameDescriptionType
degreeมุมที่ต้องการหมุนภาพFloat

Returns

TypeDescription
Optional(UIImage)Return UIImage ของภาพที่ทำการหมุนแล้ว