/// <summary> /// Ensures the result is a success /// by throwing an exception when that's not the case. /// </summary> /// <param name="result">The result returned by Skia.</param> public static void EnsureSuccess(SKCodecResult result) { if (result != SKCodecResult.Success) { throw new SkiaCodecException(result); } }
public static SKCodec Create(SKStream stream, out SKCodecResult result) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } var codec = GetObject <SKCodec> (SkiaApi.sk_codec_new_from_stream(stream.Handle, out result)); stream.RevokeOwnership(); return(codec); }
public static SKCodec Create(string filename, out SKCodecResult result) { var stream = SKFileStream.OpenStream(filename); if (stream == null) { result = SKCodecResult.InternalError; return(null); } return(Create(stream, out result)); }
public static SKCodec Create(SKStream stream, out SKCodecResult result) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (stream is SKFileStream filestream && !filestream.IsValid) throw new ArgumentException("File stream was not valid.", nameof(stream)); fixed(SKCodecResult *r = &result) { var codec = GetObject(SkiaApi.sk_codec_new_from_stream(stream.Handle, r)); stream.RevokeOwnership(codec); return(codec); } }
private SKBitmap LoadBitmap(Stream stream, out SKEncodedOrigin origin) { using SKManagedStream s = new SKManagedStream(stream); using SKCodec codec = SKCodec.Create(s); origin = codec.EncodedOrigin; SKImageInfo info = codec.Info; SKBitmap bitmap = new SKBitmap(info.Width, info.Height, SKImageInfo.PlatformColorType, info.IsOpaque ? SKAlphaType.Opaque : SKAlphaType.Premul); SKCodecResult result = codec.GetPixels(bitmap.Info, bitmap.GetPixels(out IntPtr length)); if (result == SKCodecResult.Success || result == SKCodecResult.IncompleteInput) { return(bitmap); } else { throw new ArgumentException("Unable to load bitmap from provided data"); } }
public static SKCodec Create(Stream stream, out SKCodecResult result) => Create(WrapManagedStream(stream), out result);
/// <summary> /// Initializes a new instance of the <see cref="SkiaCodecException" /> class /// with a specified error message. /// </summary> /// <param name="result">The non-successful codec result returned by Skia.</param> /// <param name="message">The message that describes the error.</param> public SkiaCodecException(SKCodecResult result, string message) : base(message) { CodecResult = result; }
/// <summary> /// Initializes a new instance of the <see cref="SkiaCodecException" /> class. /// </summary> /// <param name="result">The non-successful codec result returned by Skia.</param> public SkiaCodecException(SKCodecResult result) : base() { CodecResult = result; }