我正在开发一款 iOS 应用程序,它允许用户拍摄一系列照片 - 然后将照片放入动画中并导出为 MP4 和 GIF。
虽然 MP4 呈现源质量,但 GIF 颜色等级是可见的。
这是视觉比较:
动图:
MP4
我用于导出为 GIF 的代码:
var dictFile = new NSMutableDictionary();
var gifDictionaryFile = new NSMutableDictionary();
gifDictionaryFile.Add(ImageIO.CGImageProperties.GIFLoopCount, NSNumber.FromFloat(0));
dictFile.Add(ImageIO.CGImageProperties.GIFDictionary, gifDictionaryFile);
var dictFrame = new NSMutableDictionary();
var gifDictionaryFrame = new NSMutableDictionary();
gifDictionaryFrame.Add(ImageIO.CGImageProperties.GIFDelayTime, NSNumber.FromFloat(0f));
dictFrame.Add(ImageIO.CGImageProperties.GIFDictionary, gifDictionaryFrame);
InvokeOnMainThread(() =>
{
var imageDestination = CGImageDestination.Create(fileURL, MobileCoreServices.UTType.GIF, _images.Length);
imageDestination.SetProperties(dictFile);
for (int i = 0; i < this._images.Length; i++)
{
imageDestination.AddImage(this._images[i].CGImage, dictFrame);
}
imageDestination.Close();
});
Run Code Online (Sandbox Code Playgroud)
我用于导出为 MP4 的代码:
var videoSettings = new NSMutableDictionary(); …
Run Code Online (Sandbox Code Playgroud)