An app I'm working on needs to dynamically generate bitmap images using vector drawing commands. There are two desired targets: a alpha-channel-friendly bitmap file like .PNG and an ImageSource for binding to Xamarin Forms Image controls, creating and updating app-level DynamicResources, etc.
What is the best way to go about this? Do SKBitmap or SKImage objects have a way to convert to a Bitmap or ImageSource object? Does the SKData object need to produce the raw bytes, and then those are used to hydrate a bitmap object?
You should be able to call SKImage'.Encode() method, which will return an SKData.
Then you can create an UnmanagedMemoryStream from the Data/Size properties, and pass that to the Xamarin.Forms.StreamImageSource.
For the next version, I added a convenience AsStream() method on SKData that will allow you to more conveniently get a stream out of an SKData.
Answers
You should be able to call SKImage'.Encode() method, which will return an SKData.
Then you can create an UnmanagedMemoryStream from the Data/Size properties, and pass that to the Xamarin.Forms.StreamImageSource.
For the next version, I added a convenience AsStream() method on SKData that will allow you to more conveniently get a stream out of an SKData.
Is there a way to do this in the opposite direction? I am trying to convert an image to an SKCanvas, annotate on it, and then save that annotated SKCanvas as an image.
@MigueldeIcaza
Draw the image into your Canvas.