# Suggestion: Improve QRCode ToPng() API and Add Output Size/Scale Options

**URL:** <https://forum.radzen.com/t/suggestion-improve-qrcode-topng-api-and-add-output-size-scale-options/21616>\
**Category:** Radzen.Blazor Components\
**Created:** [July 2, 2026, 4:54pm UTC](https://forum.radzen.com/t/suggestion-improve-qrcode-topng-api-and-add-output-size-scale-options/21616 "2026-07-02T16:54:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thanh](https://forum.radzen.com/user_avatar/forum.radzen.com/thanh/32/20361_2.png) [@Thanh](https://forum.radzen.com/u/Thanh)\
**Post date:** [July 2, 2026, 4:54pm UTC](https://forum.radzen.com/t/suggestion-improve-qrcode-topng-api-and-add-output-size-scale-options/21616/1 "2026-07-02T16:54:57Z")

</div>

Hi Radzen team,

First of all, thank you for providing the QRCode component. It works well and is very easy to use.

I have a small API suggestion that I believe would make it much more flexible.

### Current behavior

Currently there are two export methods:

- `ToSvg()` returns the SVG content as a string.

- `ToPng()` converts the SVG to PNG and immediately downloads the image.

This makes `ToPng()` difficult to use in scenarios where developers need the PNG data instead of downloading it directly, such as:

- Saving to a database

- Returning the image from an API

- Embedding it into a PDF or Word document

- Processing it further before sending it to the client

- Uploading it to cloud storage

### Suggested changes

Instead of the current behavior, I would suggest separating the two responsibilities:

- Keep the current download functionality, but rename it to something like:

- Change `ToPng()` so that it returns the generated PNG instead of downloading it automatically, for example:

This would make the API more consistent with `ToSvg()`, which already returns the generated content instead of triggering a download.

### Output size / scale

It would also be very useful if both `DownloadPng()` and `ToPng()` accepted optional parameters to control the output size, for example:

- width

- height

- scale

This would allow developers to generate higher-resolution QR codes without having to post-process the image themselves.

Example:

```auto
var png = qrCode.ToPng(width: 1000, height: 1000);
// or
var png = qrCode.ToPng(scale: 4);

```

### Benefits

- Better separation of responsibilities.

- More consistent API design.

- Supports many server-side and document-generation scenarios.

- Gives developers control over the output resolution.

- Existing download functionality can still be preserved through `DownloadPng()`.

I think these changes would make the QRCode API much more flexible while remaining fully backward compatible if `DownloadPng()` is introduced alongside the new `ToPng()` behavior.

Thank you for considering this suggestion!

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [July 3, 2026, 5:19am UTC](https://forum.radzen.com/t/suggestion-improve-qrcode-topng-api-and-add-output-size-scale-options/21616/2 "2026-07-03T05:19:09Z")

</div>

Thanks for the suggestion! We accept pull requests!

---

<div class="post-metadata">

**Author:** ![Thanh](https://forum.radzen.com/user_avatar/forum.radzen.com/thanh/32/20361_2.png) [@Thanh](https://forum.radzen.com/u/Thanh)\
**Post date:** [July 3, 2026, 8:03am UTC](https://forum.radzen.com/t/suggestion-improve-qrcode-topng-api-and-add-output-size-scale-options/21616/3 "2026-07-03T08:03:25Z")

</div>

Thanks for the response!

I'd be happy to contribute, but at the moment I only have an implementation that uses SkiaSharp to convert SVG to PNG. I'm not sure whether adding a dependency on SkiaSharp would be acceptable for Radzen, or if you'd prefer a solution without introducing any additional dependencies.

If SkiaSharp isn't suitable, I'd appreciate any guidance on the preferred approach for implementing this feature within the project.

```auto
 public static byte[] ConvertSvgToPng(string svgContent, int outputSize)
 {
     using var skSvg = new SKSvg();
     skSvg.FromSvg(svgContent);

     if (skSvg.Picture is null)
         return [];

     var bounds = skSvg.Picture.CullRect;

     using var surface = SKSurface.Create(
         new SKImageInfo(
             outputSize,
             outputSize,
             SKColorType.Rgba8888,
             SKAlphaType.Premul));

     if (surface is null)
         return [];

     var canvas = surface.Canvas;
     canvas.Clear(SKColors.Transparent);

     float scale = Math.Min(
         outputSize / bounds.Width,
         outputSize / bounds.Height);

     float scaledWidth = bounds.Width * scale;
     float scaledHeight = bounds.Height * scale;

     float offsetX = (outputSize - scaledWidth) / 2f;
     float offsetY = (outputSize - scaledHeight) / 2f;

     canvas.Translate(offsetX, offsetY);
     canvas.Scale(scale);
     canvas.Translate(-bounds.Left, -bounds.Top);

     using var paint = new SKPaint
     {
         IsAntialias = true
     };

     canvas.DrawPicture(skSvg.Picture, paint);
     canvas.Flush();

     using var image = surface.Snapshot();
     using var data = image.Encode(SKEncodedImageFormat.Png, 100);

     return data?.ToArray() ?? [];
 }

```

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [July 3, 2026, 1:00pm UTC](https://forum.radzen.com/t/suggestion-improve-qrcode-topng-api-and-add-output-size-scale-options/21616/4 "2026-07-03T13:00:26Z")

</div>

No, third party are not acceptable. I’ll push overload with requested functionallty.

---

<div class="post-metadata">

**Author:** ![Thanh](https://forum.radzen.com/user_avatar/forum.radzen.com/thanh/32/20361_2.png) [@Thanh](https://forum.radzen.com/u/Thanh)\
**Post date:** [July 3, 2026, 4:21pm UTC](https://forum.radzen.com/t/suggestion-improve-qrcode-topng-api-and-add-output-size-scale-options/21616/5 "2026-07-03T16:21:37Z")

</div>

Thanks! That sounds great.

I completely understand the decision to avoid third-party dependencies. Adding overloads with the requested functionality would cover my use case perfectly.

Thank you for considering the suggestion and for your quick response!
