private async Task <Stream> GetImageStreamInternal(SignatureImageFormat format, Size scale, Rect signatureBounds, Size imageSize, float strokeWidth, Color strokeColor, Color backgroundColor) { CanvasBitmapFileFormat cbff; if (format == SignatureImageFormat.Jpeg) { cbff = CanvasBitmapFileFormat.Jpeg; } else if (format == SignatureImageFormat.Png) { cbff = CanvasBitmapFileFormat.Png; } else { return(null); } using (var offscreen = GetRenderTarget(scale, signatureBounds, imageSize, strokeWidth, strokeColor, backgroundColor)) { var fileStream = new InMemoryRandomAccessStream(); await offscreen.SaveAsync(fileStream, cbff); var stream = fileStream.AsStream(); stream.Position = 0; return(stream); } }
/// <summary> /// Returns an image data stream for the current signature. /// (The caller must dispose the stream) /// </summary> /// <param name="imageFormat">The format/encoding of the image that is desired.</param> /// <returns>Returns the image data stream.</returns> public Task <Stream> GetImageStreamAsync(SignatureImageFormat imageFormat) { var args = new ImageStreamRequestedEventArgs(imageFormat); ImageStreamRequested?.Invoke(this, args); return(args.ImageStreamTask); }
/// <summary> /// Create an encoded image stream of the currently drawn signature using the specified settings. /// </summary> public Task <Stream> GetImageStreamAsync(SignatureImageFormat imageFormat, ImageConstructionSettings settings) { var args = new ImageStreamRequestedEventArgs(imageFormat, settings); ImageStreamRequested?.Invoke(this, args); return(args.ImageStreamTask); }
/// <summary> /// Create an encoded image stream of the currently drawn signature at the specified scale. /// </summary> public Task <Stream> GetImageStreamAsync(SignatureImageFormat format, float scale, bool shouldCrop = true, bool keepAspectRatio = true) { return(GetImageStreamAsync(format, new ImageConstructionSettings { ShouldCrop = shouldCrop, DesiredSizeOrScale = new SizeOrScale(scale, SizeOrScaleType.Scale, keepAspectRatio) })); }
/// <summary> /// Create an encoded image stream of the currently drawn signature at the specified scale with the specified stroke and background colors. /// </summary> public Task <Stream> GetImageStreamAsync(SignatureImageFormat format, NativeColor strokeColor, NativeColor fillColor, float scale, bool shouldCrop = true, bool keepAspectRatio = true) { return(GetImageStreamAsync(format, new ImageConstructionSettings { ShouldCrop = shouldCrop, StrokeColor = strokeColor, BackgroundColor = fillColor, DesiredSizeOrScale = new SizeOrScale(scale, SizeOrScaleType.Scale, keepAspectRatio) })); }
/// <summary> /// Create an encoded image stream of the currently drawn signature using the specified settings. /// </summary> public Task <Stream> GetImageStreamAsync(SignatureImageFormat format, ImageConstructionSettings settings) { NativeSize scale; NativeRect signatureBounds; NativeSize imageSize; float strokeWidth; NativeColor strokeColor; NativeColor backgroundColor; if (GetImageConstructionArguments(settings, out scale, out signatureBounds, out imageSize, out strokeWidth, out strokeColor, out backgroundColor)) { return(GetImageStreamInternal(format, scale, signatureBounds, imageSize, strokeWidth, strokeColor, backgroundColor)); } return(Task.FromResult <Stream> (null)); }
private Task <Stream> GetImageStreamInternal(SignatureImageFormat format, CGSize scale, CGRect signatureBounds, CGSize imageSize, float strokeWidth, UIColor strokeColor, UIColor backgroundColor) { var image = GetImageInternal(scale, signatureBounds, imageSize, strokeWidth, strokeColor, backgroundColor); if (image != null) { if (format == SignatureImageFormat.Jpeg) { return(Task.Run(() => image.AsJPEG().AsStream())); } else if (format == SignatureImageFormat.Png) { return(Task.Run(() => image.AsPNG().AsStream())); } } return(Task.FromResult <Stream> (null)); }
private string AcceptType(SignatureImageFormat format) { switch (format) { case SignatureImageFormat.PNG: return("image/png"); case SignatureImageFormat.JPG: return("image/jpeg"); case SignatureImageFormat.GIF: return("image/gif"); default: throw new EslException("Unknown SignatureImageFormat: " + format, null); } }
public DownloadedFile GetSignatureImageForSender(string senderId, SignatureImageFormat format) { string path = template.UrlFor(UrlTemplate.SIGNATURE_IMAGE_FOR_SENDER_PATH) .Replace("{senderId}", senderId) .Build(); try { return(client.GetBytes(path, AcceptType(format))); } catch (EslServerException e) { throw new EslServerException("Could not download signature image for sender." + " Exception: " + e.Message, e.ServerError, e); } catch (Exception e) { throw new EslException("Could not download signature image for sender." + " Exception: " + e.Message, e); } }
private Task <Stream> GetImageStreamInternal(SignatureImageFormat format, Size scale, Rect signatureBounds, Size imageSize, float strokeWidth, Color strokeColor, Color backgroundColor) { var image = GetImageInternal(scale, signatureBounds, imageSize, strokeWidth, strokeColor, backgroundColor); if (image != null) { if (format == SignatureImageFormat.Jpeg) { var stream = new MemoryStream(); image.SaveJpeg(stream, image.PixelWidth, image.PixelHeight, 0, 100); return(Task.FromResult <Stream> (stream)); } else if (format == SignatureImageFormat.Png) { var stream = new MemoryStream(); var encoder = new PngEncoder(); encoder.Encode(image.ToImage(), stream); return(Task.FromResult <Stream> (stream)); } } return(Task.FromResult <Stream> (null)); }
private async Task <Stream> GetImageStreamInternal(SignatureImageFormat format, System.Drawing.SizeF scale, System.Drawing.RectangleF signatureBounds, System.Drawing.SizeF imageSize, float strokeWidth, Color strokeColor, Color backgroundColor) { Bitmap.CompressFormat bcf; if (format == SignatureImageFormat.Jpeg) { bcf = Bitmap.CompressFormat.Jpeg; } else if (format == SignatureImageFormat.Png) { bcf = Bitmap.CompressFormat.Png; } else { return(null); } var image = GetImageInternal(scale, signatureBounds, imageSize, strokeWidth, strokeColor, backgroundColor); if (image != null) { using (image) { var stream = new MemoryStream(); var result = await image.CompressAsync(bcf, 100, stream); image.Recycle(); if (result) { stream.Position = 0; return(stream); } } } return(null); }
/// <summary> /// Create an encoded image of the currently drawn signature at the specified size with the specified stroke color. /// </summary> public Task <Stream> GetImageStreamAsync(SignatureImageFormat format, Color strokeColor, System.Drawing.SizeF size, bool shouldCrop = true, bool keepAspectRatio = true) { return(SignaturePadCanvas.GetImageStreamAsync(format, strokeColor, size, shouldCrop, keepAspectRatio)); }
public DownloadedFile GetSignatureImageForPackageRole(PackageId packageId, string signerId, SignatureImageFormat format) { string path = template.UrlFor(UrlTemplate.SIGNATURE_IMAGE_FOR_PACKAGE_ROLE_PATH) .Replace("{packageId}", packageId.Id) .Replace("{roleId}", signerId) .Build(); try { return(client.GetBytes(path, AcceptType(format))); } catch (EslServerException e) { throw new EslServerException("Could not download signature image for package signer." + " Exception: " + e.Message, e.ServerError, e); } catch (Exception e) { throw new EslException("Could not download signature image for package signer." + " Exception: " + e.Message, e); } }
/// <summary> /// Create an encoded image of the currently drawn signature using the specified settings. /// </summary> public Task <Stream> GetImageStreamAsync(SignatureImageFormat format, ImageConstructionSettings settings) { return(SignaturePadCanvas.GetImageStreamAsync(format, settings)); }
/// <summary> /// Create an encoded image of the currently drawn signature at the specified scale with the specified stroke and background colors. /// </summary> public Task <Stream> GetImageStreamAsync(SignatureImageFormat format, Color strokeColor, Color fillColor, float scale, bool shouldCrop = true, bool keepAspectRatio = true) { return(SignaturePadCanvas.GetImageStreamAsync(format, strokeColor, fillColor, scale, shouldCrop, keepAspectRatio)); }
/// <summary> /// Create an encoded image of the currently drawn signature at the specified size. /// </summary> public Task <Stream> GetImageStreamAsync(SignatureImageFormat format, Size size, bool shouldCrop = true, bool keepAspectRatio = true) { return(SignaturePadCanvas.GetImageStreamAsync(format, size, shouldCrop, keepAspectRatio)); }
public ImageStreamRequestedEventArgs(SignatureImageFormat imageFormat, ImageConstructionSettings settings) { ImageFormat = imageFormat; Settings = settings; }
public ImageStreamRequestedEventArgs(SignatureImageFormat imageFormat) { ImageFormat = imageFormat; }