public static SKImageInfo DecodeBounds(byte[] buffer, SKColorType pref = SKColorType.Unknown) { SKImageInfo info; SKImageDecoder.DecodeMemoryBounds(buffer, out info, pref); return(info); }
public static SKImageInfo DecodeBounds(string filename, SKColorType pref = SKColorType.Unknown) { SKImageInfo info; SKImageDecoder.DecodeFileBounds(filename, out info, pref); return(info); }
public static SKImageInfo DecodeBounds(SKStreamRewindable stream, SKColorType pref = SKColorType.Unknown) { SKImageInfo info; SKImageDecoder.DecodeStreamBounds(stream, out info, pref); return(info); }
public static SKBitmap Decode(byte[] buffer, SKColorType pref = SKColorType.Unknown) { var bitmap = new SKBitmap(); if (!SKImageDecoder.DecodeMemory(buffer, bitmap, pref)) { bitmap.Dispose(); bitmap = null; } return(bitmap); }
public static SKBitmap Decode(string filename, SKColorType pref = SKColorType.Unknown) { var bitmap = new SKBitmap(); if (!SKImageDecoder.DecodeFile(filename, bitmap, pref)) { bitmap.Dispose(); bitmap = null; } return(bitmap); }
public static SKBitmap Decode(SKStreamRewindable stream, SKColorType pref = SKColorType.Unknown) { var bitmap = new SKBitmap(); if (!SKImageDecoder.DecodeStream(stream, bitmap, pref)) { bitmap.Dispose(); bitmap = null; } return(bitmap); }
public static void BitmapDecoder(SKCanvas canvas, int width, int height) { var assembly = typeof(Demos).GetTypeInfo().Assembly; var imageName = assembly.GetName().Name + ".color-wheel.png"; canvas.Clear(SKColors.White); // load the embedded resource stream using (var resource = assembly.GetManifestResourceStream(imageName)) using (var stream = new SKManagedStream(resource)) using (var decoder = new SKImageDecoder(stream)) using (var paint = new SKPaint()) using (var tf = SKTypeface.FromFamilyName("Arial")) { paint.IsAntialias = true; paint.TextSize = 14; paint.Typeface = tf; paint.Color = SKColors.Black; // read / set decoder settings decoder.DitherImage = true; decoder.PreferQualityOverSpeed = true; decoder.SampleSize = 2; // decode the image using (var bitmap = new SKBitmap()) { var result = decoder.Decode(stream, bitmap); if (result != SKImageDecoderResult.Failure) { var info = bitmap.Info; var x = 25; var y = 25; canvas.DrawBitmap(bitmap, x, y); x += info.Width + 25; y += 14; canvas.DrawText(string.Format("Result: {0}", result), x, y, paint); y += 20; canvas.DrawText(string.Format("Size: {0}px x {1}px", bitmap.Width, bitmap.Height), x, y, paint); y += 20; canvas.DrawText(string.Format("Pixels: {0} @ {1}b/px", bitmap.Pixels.Length, bitmap.BytesPerPixel), x, y, paint); } } } }