コード例 #1
0
 /// <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);
     }
 }
コード例 #2
0
ファイル: SKCodec.cs プロジェクト: superowner/SkiaSharp
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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");
            }
        }
コード例 #6
0
 public static SKCodec Create(Stream stream, out SKCodecResult result) =>
 Create(WrapManagedStream(stream), out result);
コード例 #7
0
 /// <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;
 }
コード例 #8
0
 /// <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;
 }