Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nikvoronin/xamltobitmap.render
Renders XAML with binded data context into the in-memory bitmap stream.
https://github.com/nikvoronin/xamltobitmap.render
csharp dotnet windows windows-presentation-foundation wpf xaml
Last synced: 2 days ago
JSON representation
Renders XAML with binded data context into the in-memory bitmap stream.
- Host: GitHub
- URL: https://github.com/nikvoronin/xamltobitmap.render
- Owner: nikvoronin
- License: mit
- Created: 2023-08-25T19:12:20.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-30T22:04:12.000Z (9 months ago)
- Last Synced: 2024-10-17T17:13:37.380Z (20 days ago)
- Topics: csharp, dotnet, windows, windows-presentation-foundation, wpf, xaml
- Language: C#
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# XamlToBitmap.Render
Renders XAML with binded data context into the in-memory bitmap stream.
## How to use
```csharp
public async Task Main()
{
await RenderToBitmap(
"./assets/weather-template.xaml",
// Use streams not strings! This is just a short example.
JsonSerializer.Deserialize(
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;
```