Importing .gif file to xcode simulator by simply dragging file from system was getting converted into .png file automatically.
Asked
Active
Viewed 440 times
-5
-
http://stackoverflow.com/a/16996915/294884 – Fattie Aug 27 '15 at 12:16
-
possible duplicate of [Convert Images to gif using ios](http://stackoverflow.com/questions/16996690/convert-images-to-gif-using-ios) – Eric Aya Aug 27 '15 at 16:04
-
The title of the question I've linked is not the same as yours but the accepted answers contains your solution. – Eric Aya Aug 27 '15 at 16:05
1 Answers
0
If you want to import gif file from Xcode's simulator camera library, make sure you download the .gif file from simulator's safari or save gif from your application to camera library. If we import .gif file to xcode simulator by simply dragging file from system, it will automatically get converted into .png file.
let savingPath : AnyObject = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)[0]
var library:ALAssetsLibrary? = ALAssetsLibrary()
var referenceURL : NSURL = info[UIImagePickerControllerReferenceURL] as! NSURL
library!.assetForURL(referenceURL, resultBlock: { (asset : ALAsset!) -> Void in
var assetRep : ALAssetRepresentation = asset.defaultRepresentation()
let sizeOfRawDataInBytes: Int = Int(assetRep.size())
var rawData: NSMutableData = NSMutableData(length: sizeOfRawDataInBytes)!
var bufferPtr: UnsafeMutablePointer<Void> = rawData.mutableBytes
var bufferPtr8: UnsafeMutablePointer<UInt8> = UnsafeMutablePointer<UInt8>(bufferPtr)
var error: NSError? = nil
var buffered = assetRep.getBytes(bufferPtr8, fromOffset: 0, length: sizeOfRawDataInBytes, error: &error)
let newData: NSData = NSData(bytesNoCopy: bufferPtr8, length: buffered, freeWhenDone: false)
newData.writeToFile( savingPath , atomically: true)

sourabh sharotria
- 77
- 1
- 5