Inheritance: SKObject
Exemple #1
0
 public static SKBitmap Decode(SKStream stream)
 {
     if (stream == null)
     {
         throw new ArgumentNullException(nameof(stream));
     }
     using (var codec = SKCodec.Create(stream)) {
         if (codec == null)
         {
             return(null);
         }
         return(Decode(codec));
     }
 }
Exemple #2
0
 public static SKBitmap Decode(SKData data, SKImageInfo bitmapInfo)
 {
     if (data == null)
     {
         throw new ArgumentNullException(nameof(data));
     }
     using (var codec = SKCodec.Create(data)) {
         if (codec == null)
         {
             return(null);
         }
         return(Decode(codec, bitmapInfo));
     }
 }
Exemple #3
0
 public static SKBitmap Decode(string filename, SKImageInfo bitmapInfo)
 {
     if (filename == null)
     {
         throw new ArgumentNullException(nameof(filename));
     }
     using (var codec = SKCodec.Create(filename)) {
         if (codec == null)
         {
             return(null);
         }
         return(Decode(codec, bitmapInfo));
     }
 }
Exemple #4
0
        public static SKBitmap Decode(byte[] buffer, SKImageInfo bitmapInfo)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            fixed(byte *b = buffer)
            {
                using (var skdata = SKData.Create((IntPtr)b, buffer.Length))
                    using (var codec = SKCodec.Create(skdata)) {
                        return(Decode(codec, bitmapInfo));
                    }
            }
        }
Exemple #5
0
        public static SKImageInfo DecodeBounds(byte[] buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            fixed(byte *b = buffer)
            {
                using (var skdata = SKData.Create((IntPtr)b, buffer.Length))
                    using (var codec = SKCodec.Create(skdata)) {
                        return(codec?.Info ?? SKImageInfo.Empty);
                    }
            }
        }
Exemple #6
0
 public static SKImage FromEncodedData(SKStream data)
 {
     if (data == null)
     {
         throw new ArgumentNullException(nameof(data));
     }
     using (var codec = SKCodec.Create(data))
         using (var bitmap = SKBitmap.Decode(codec, codec.Info)) {
             if (bitmap == null)
             {
                 return(null);
             }
             return(FromBitmap(bitmap));
         }
 }
Exemple #7
0
        public static SKBitmap Decode(SKCodec codec)
        {
            if (codec == null)
            {
                throw new ArgumentNullException(nameof(codec));
            }
            var info = codec.Info;

            if (info.AlphaType == SKAlphaType.Unpremul)
            {
                info.AlphaType = SKAlphaType.Premul;
            }
            // for backwards compatibility, remove the colorspace
            info.ColorSpace = null;
            return(Decode(codec, info));
        }
Exemple #8
0
 public static SKImage FromEncodedData(string filename)
 {
     if (filename == null)
     {
         throw new ArgumentNullException(nameof(filename));
     }
     using (var stream = SKBitmap.OpenStream(filename))
         using (var codec = SKCodec.Create(stream))
             using (var bitmap = SKBitmap.Decode(codec, codec.Info)) {
                 if (bitmap == null)
                 {
                     return(null);
                 }
                 return(FromBitmap(bitmap));
             }
 }
Exemple #9
0
        public static SKBitmap Decode(SKCodec codec, SKImageInfo bitmapInfo)
        {
            if (codec == null)
            {
                throw new ArgumentNullException(nameof(codec));
            }

            var bitmap = new SKBitmap(bitmapInfo);
            var result = codec.GetPixels(bitmapInfo, bitmap.GetPixels(out var length));

            if (result != SKCodecResult.Success && result != SKCodecResult.IncompleteInput)
            {
                bitmap.Dispose();
                bitmap = null;
            }
            return(bitmap);
        }
Exemple #10
0
		public static SKBitmap Decode (SKCodec codec)
		{
			if (codec == null) {
				throw new ArgumentNullException (nameof (codec));
			}
			return Decode (codec, codec.Info);
		}
Exemple #11
0
		public static SKBitmap Decode (SKCodec codec, SKImageInfo bitmapInfo)
		{
			if (codec == null) {
				throw new ArgumentNullException (nameof (codec));
			}

			// construct a color table for the decode if necessary
			SKColorTable colorTable = null;
			int colorCount = 0;
			if (bitmapInfo.ColorType == SKColorType.Index8)
			{
				colorTable = new SKColorTable ();
			}

			// read the pixels and color table
			var bitmap = new SKBitmap (bitmapInfo, colorTable);
			IntPtr length;
			var result = codec.GetPixels (bitmapInfo, bitmap.GetPixels (out length), colorTable, ref colorCount);
			if (result != SKCodecResult.Success && result != SKCodecResult.IncompleteInput) {
				bitmap.Dispose ();
				bitmap = null;
			}
			return bitmap;
		}
Exemple #12
0
 public static SKBitmap Decode(SKData data)
 {
     using (var codec = SKCodec.Create(data)) {
         return(Decode(codec));
     }
 }
Exemple #13
0
 public static SKBitmap Decode(SKStream stream)
 {
     using (var codec = SKCodec.Create(stream)) {
         return(Decode(codec));
     }
 }
Exemple #14
0
 public static SKImageInfo DecodeBounds(SKData data)
 {
     using (var codec = SKCodec.Create(data)) {
         return(codec.Info);
     }
 }
Exemple #15
0
 public static SKImageInfo DecodeBounds(SKStream stream)
 {
     using (var codec = SKCodec.Create(stream)) {
         return(codec.Info);
     }
 }