Support for the display of various image/picture types (e.g., bitmaps)
See original GitHub issueIs your feature request related to a problem? Please describe. I would like to have images displayed in a .NET Interactive Notebook when working in Visual Studio Code with the .NET Interactive Notebooks extension. In particular, support for displaying SkiaSharp elements, such as images, bitmaps, etc. would be great.
Describe the solution you’d like An example script might be:
#r "nuget: SkiaSharp"
open SkiaSharp
let bitmap = new SKBitmap(200, 200) // creates a default SKBitmap
// do some stuff to the bitmap, such as calling bitmap.SetPixel to manually set pixels
let image = SKImage.FromBitmap(bitmap) // creates an SKImage from a bitmap
let data = image.Encode() // encodes the image as a PNG
Then I’d like either of bitmap
, image
, or data
left as the last element in the cell to have the underlying image displayed in the cell output, just as XPlot.Plotly does with its various charts and plots. The code above actually all works inside a notebook right now, and I’m able to save the image to a file. But I’d love the image to just directly appear in the cell’s output.
For example:
If this is possible right now, then I am not sure how to get it to happen and would love any pointers if it is possible.
Describe alternatives you’ve considered I considered trying to load various views that would load external to notebook, such as using SkiaSharp.Views.Forms, Xamarin.Forms, etc. However, that’s not much different than just running things in an F# script (.fsx file). Having the image immediately displayed would be fantastic for all sorts of use cases.
Edit: I edited it because I submitted by accident while creating it.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:24 (20 by maintainers)
Top GitHub Comments
@rdthree SkiaSharp is a general API for drawing. For .NET Interactive notebooks, one can implement some custom formatters so that datatypes get specially displayed in the notebook (such as Plotly.NET). To get the interactive behavior, you sometimes need to reference another Nuget package (such as how Plotly.NET does it). I think @mattleibow’s plan was to include the SkiaSharp extension in the already existing Nuget package, so you wouldn’t need to separately reference an extension package. He added some basic support (see here and here), but I’m not sure if it got released in a Nuget release and/or if it’s still current. I believe he did it as a quick trial implementation where it wasn’t intended to be feature complete.
I didn’t know
surface.Snapshot().Display()
would work like that, so maybe that’s the extension at work (?) or some new features of .NET Interactive (?). Someone else would know. I just created this feature suggestion. 😃In the latest previews of SkiaSharp I added some elements, but I also had to use base64.
Would be cool to be able to do this automatically. And if it supports images, it might be nice for workbooks to have some basic info like size and stuff.