2
MacOS/osx에서 Swift를 사용하여 NSImages 배열을 변환하는 방법이 있는지 궁금합니다.Swift (MacOS)를 사용하여 이미지에서 GIF 만들기
나중에 파일로 내보낼 수 있어야하므로 내 앱에 표시되는 이미지 애니메이션으로 충분하지 않습니다.
감사합니다.
MacOS/osx에서 Swift를 사용하여 NSImages 배열을 변환하는 방법이 있는지 궁금합니다.Swift (MacOS)를 사용하여 이미지에서 GIF 만들기
나중에 파일로 내보낼 수 있어야하므로 내 앱에 표시되는 이미지 애니메이션으로 충분하지 않습니다.
감사합니다.
이미지 I/O에는 필요한 기능이 있습니다. 시도해보십시오.
var images = ... // init your array of NSImage
let destinationURL = NSURL(fileURLWithPath: "/path/to/image.gif")
let destinationGIF = CGImageDestinationCreateWithURL(destinationURL, kUTTypeGIF, images.count, nil)!
// The final size of your GIF. This is an optional parameter
var rect = NSMakeRect(0, 0, 350, 250)
// This dictionary controls the delay between frames
// If you don't specify this, CGImage will apply a default delay
let properties = [
(kCGImagePropertyGIFDictionary as String): [(kCGImagePropertyGIFDelayTime as String): 1.0/16.0]
]
for img in images {
// Convert an NSImage to CGImage, fitting within the specified rect
// You can replace `&rect` with nil
let cgImage = img.CGImageForProposedRect(&rect, context: nil, hints: nil)!
// Add the frame to the GIF image
// You can replace `properties` with nil
CGImageDestinationAddImage(destinationGIF, cgImage, properties)
}
// Write the GIF file to disk
CGImageDestinationFinalize(destinationGIF)
"방법이 있습니까"에 따라 달라집니다. 거기에 당신이 직접 코딩 할 수 있다는 의미에서 "방법입니다"하지만 Foundation 또는 Cocoa에서 NSGIF (imageSequence :)와 같은 API는 없다고 생각합니다. – zneak
나는 이해한다. 라이브러리 또는 샘플 코드를 쉽게 구현할 수있을 것이라고 생각하십니까? –
실제로 [Image I/O] (https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/ImageIORefCollection/index.html#//apple_ref/doc/uid)를 살펴볼 수 있습니다./TP40005102) framework ([example] (http://stackoverflow.com/questions/14915138/create-and-and-export-an-animated-gif-via-ios)). – zneak