/// <summary> /// Writes the resulting graphics as a PNG image to the specified stream. /// <para> /// The canvas can no longer be used for drawing after calling this method.</para> /// </summary> /// <param name="stream">The stream to write to.</param> public void WriteTo(Stream stream) { _canvas.Dispose(); _canvas = null; using (var image = SKImage.FromBitmap(_bitmap)) using (var data = image.Encode(SKEncodedImageFormat.Png, 90)) using (var imageDataStream = data.AsStream()) { PngProcessor.InsertDpi(imageDataStream, stream, _dpi); } Close(); }
/// <summary> /// Writes the resulting graphics as a PNG image to the specified file path. /// <para> /// The canvas can no longer be used for drawing after calling this method.</para> /// </summary> /// <param name="path">The path (file name) to write to.</param> public void SaveAs(string path) { _canvas.Dispose(); _canvas = null; using (var image = SKImage.FromBitmap(_bitmap)) using (var data = image.Encode(SKEncodedImageFormat.Png, 90)) using (var imageDataStream = data.AsStream()) using (var stream = File.OpenWrite(path)) { PngProcessor.InsertDpi(imageDataStream, stream, _dpi); } Close(); }
/// <summary> /// Gets the resulting graphics encoded as a PNG image in a byte array. /// <para> /// The canvas can no longer be used for drawing after calling this method.</para> /// </summary> /// <returns>The byte array containing the PNG image</returns> public override byte[] ToByteArray() { _canvas.Dispose(); _canvas = null; byte[] result; using (var image = SKImage.FromBitmap(_bitmap)) using (var data = image.Encode(SKEncodedImageFormat.Png, 90)) using (var imageDataStream = data.AsStream()) { var buffer = new MemoryStream(); PngProcessor.InsertDpi(imageDataStream, buffer, _dpi); result = buffer.ToArray(); } Close(); return(result); }