Skip to content

Renders XAML with binded data context into the in-memory bitmap stream.

License

Notifications You must be signed in to change notification settings

nikvoronin/XamlToBitmap.Render

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

XamlToBitmap.Render

Renders XAML with binded data context into the in-memory bitmap stream.

How to use

public async Task Main()
{
    await RenderToBitmap(
        "./assets/weather-template.xaml",
        // Use streams not strings! This is just a short example.
        JsonSerializer.Deserialize<WeatherForecast>(
            File.ReadAllText( "./data/forecast.json" ) ),
        new XamlRender(),
        $"./outbox/image{DateTime.Now.Ticks}.png"
    );
}

public static async Task RenderToBitmap(
    string pathToXamlFile,
    object dataContext,
    IContentRender renderer,
    string saveToPath )
{
    using Stream stream = File.OpenRead( pathToXamlFile );
    using MemoryStream imageStream =
        await renderer.RenderAsync(
            stream, dataContext,
            XamlRender.ThermalPrinter_CommonDpi,
            XamlRender.ThermalPrinter_CommonDpi );

    File.WriteAllBytes( saveToPath, imageStream.GetBuffer() );
}

public const double ThermalPrinter_HiResDpi = 304;

About

Renders XAML with binded data context into the in-memory bitmap stream.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages