[关闭]
@buoge 2017-05-31T18:23:29.000000Z 字数 667 阅读 1156

ALAsset中获取照片的原图并转换成NSData,UIImage

iOS


way1:

if let mCGImageVal = mALAsset?.defaultRepresentation().fullScreenImage().takeUnretainedValue() {
    self?.imageView.image = UIImage(cgImage: mCGImageVal)
}

way2:

http://www.hangge.com/blog/cache/detail_759.html

if let representation =  myALAsset.defaultRepresentation() {
let representationSize =Int(representation.size()) 
let imageBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: representationSize)
let bufferSize = representation.getBytes(imageBuffer, fromOffset: Int64(0),                                                   length: Int(representation.size()), error: nil)

let imgData:NSData =  NSData(bytesNoCopy:imageBuffer     ,length:bufferSize, freeWhenDone:true)
self?.imageView.image = UIImage(data: imgData as Data)

}

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注