async Task <List <string> > Upload(IList <FileData> p_uploadFiles, string p_fixedvolume, CancellationToken p_token) { _cancelToken = p_token; _boundary = Kit.NewGuid; _dataResponse = NSMutableData.Create(); _cancelToken.ThrowIfCancellationRequested(); _result = new TaskCompletionSource <List <string> >(); _cancelToken.Register(() => _result.TrySetCanceled()); _tempFile = await SaveToFile(p_uploadFiles, p_fixedvolume); var request = new NSMutableUrlRequest(NSUrl.FromString($"{Kit.Stub.ServerUrl.TrimEnd('/')}/fsm/.u")); request.HttpMethod = "POST"; request["Content-Type"] = "multipart/form-data; boundary=" + _boundary; if (Kit.IsLogon) { request.Headers["uid"] = (NSString)Kit.UserID.ToString(); } var uploadTask = _session.CreateUploadTask(request, new NSUrl(_tempFile, false)); uploadTask.Resume(); return(await _result.Task.ConfigureAwait(false)); }
protected override Task <PImage> GenerateImageFromDecoderContainerAsync(IDecodedImage <PImage> decoded, ImageInformation imageInformation, bool isPlaceholder) { PImage result; if (decoded.IsAnimated) { #if __IOS__ result = PImage.CreateAnimatedImage(decoded.AnimatedImages .Select(v => v.Image) .Where(v => v?.CGImage != null).ToArray(), decoded.AnimatedImages.Sum(v => v.Delay) / 100.0); #elif __MACOS__ using (var mutableData = NSMutableData.Create()) { var fileOptions = new CGImageDestinationOptions { GifDictionary = new NSMutableDictionary() }; fileOptions.GifDictionary[ImageIO.CGImageProperties.GIFLoopCount] = new NSString("0"); //options.GifDictionary[ImageIO.CGImageProperties.GIFHasGlobalColorMap] = new NSString("true"); using (var destintation = CGImageDestination.Create(mutableData, MobileCoreServices.UTType.GIF, decoded.AnimatedImages.Length, fileOptions)) { for (var i = 0; i < decoded.AnimatedImages.Length; i++) { var options = new CGImageDestinationOptions { GifDictionary = new NSMutableDictionary() }; options.GifDictionary[ImageIO.CGImageProperties.GIFUnclampedDelayTime] = new NSString(decoded.AnimatedImages[i].Delay.ToString()); destintation.AddImage(decoded.AnimatedImages[i].Image.CGImage, options); } destintation.Close(); } result = new PImage(mutableData); // TODO I really don't know why representations count is 1, anyone? // var test = result.Representations(); } #endif } else { result = decoded.Image; } return(Task.FromResult(result)); }
protected override Task <PImage> GenerateImageFromDecoderContainerAsync(IDecodedImage <PImage> decoded, ImageInformation imageInformation, bool isPlaceholder) { PImage result; if (decoded.IsAnimated) { #if __IOS__ result = PImage.CreateAnimatedImage(decoded.AnimatedImages .Select(v => v.Image) .Where(v => v?.CGImage != null).ToArray(), decoded.AnimatedImages.Sum(v => v.Delay) / 100.0); #elif __MACOS__ using (var mutableData = NSMutableData.Create()) { using (var destintation = CGImageDestination.Create(mutableData, MobileCoreServices.UTType.GIF, decoded.AnimatedImages.Length)) { for (int i = 0; i < decoded.AnimatedImages.Length; i++) { var options = new CGImageDestinationOptions(); options.GifDictionary = new NSMutableDictionary(); options.GifDictionary[ImageIO.CGImageProperties.GIFDelayTime] = NSNumber.FromDouble(decoded.AnimatedImages[i].Delay / 100.0d); destintation.AddImage(decoded.AnimatedImages[i].Image.CGImage, options); } destintation.Close(); } // TODO I really don't know why it's not working. Anyone? result = new PImage(mutableData); } #endif } else { result = decoded.Image; } return(Task.FromResult(result)); }