diff --git a/QRCoder/SvgQRCode.cs b/QRCoder/SvgQRCode.cs
index 25ba8c8c..81cc2486 100644
--- a/QRCoder/SvgQRCode.cs
+++ b/QRCoder/SvgQRCode.cs
@@ -285,7 +285,7 @@ public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBac
using (var bitmap = new Bitmap(iconRasterized))
{
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
- _logoData = Convert.ToBase64String(ms.GetBuffer(), Base64FormattingOptions.None);
+ _logoData = Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length, Base64FormattingOptions.None);
}
}
_mediaType = MediaType.PNG;
@@ -312,6 +312,22 @@ public SvgLogo(string iconVectorized, int iconSizePercent = 15, bool fillLogoBac
_isEmbedded = iconEmbedded;
}
+ ///
+ /// Create a logo object to be used in SvgQRCode renderer
+ ///
+ /// Logo to be rendered as PNG
+ /// Degree of percentage coverage of the QR code by the logo
+ /// If true, the background behind the logo will be cleaned
+ public SvgLogo(byte[] iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true)
+ {
+ _iconSizePercent = iconSizePercent;
+ _logoData = Convert.ToBase64String(iconRasterized, Base64FormattingOptions.None);
+ _mediaType = MediaType.PNG;
+ _fillLogoBackground = fillLogoBackground;
+ _logoRaw = iconRasterized;
+ _isEmbedded = false;
+ }
+
///
/// Returns the raw logo's data
///
diff --git a/QRCoderTests/SvgQRCodeRendererTests.cs b/QRCoderTests/SvgQRCodeRendererTests.cs
index f2d11a35..0981e6e2 100644
--- a/QRCoderTests/SvgQRCodeRendererTests.cs
+++ b/QRCoderTests/SvgQRCodeRendererTests.cs
@@ -106,7 +106,7 @@ public void can_render_svg_qrcode_without_quietzones_hex()
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
[Fact]
[Category("QRRenderer/SvgQRCode")]
- public void can_render_svg_qrcode_with_png_logo()
+ public void can_render_svg_qrcode_with_png_logo_bitmap()
{
//Create QR code
var gen = new QRCodeGenerator();
@@ -120,10 +120,29 @@ public void can_render_svg_qrcode_with_png_logo()
var svg = new SvgQRCode(data).GetGraphic(10, Color.DarkGray, Color.White, logo: logoObj);
var result = HelperFunctions.StringToHash(svg);
- result.ShouldBe("78e02e8ba415f15817d5ed88c4afca31");
+ result.ShouldBe("78e02e8ba415f15817d5ed88c4afca31");
}
#endif
+ [Fact]
+ [Category("QRRenderer/SvgQRCode")]
+ public void can_render_svg_qrcode_with_png_logo_bytearray()
+ {
+ //Create QR code
+ var gen = new QRCodeGenerator();
+ var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H);
+
+ //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346
+ var logoBitmap = System.IO.File.ReadAllBytes(GetAssemblyPath() + "\\assets\\noun_software engineer_2909346.png");
+ var logoObj = new SvgQRCode.SvgLogo(iconRasterized: logoBitmap, 15);
+ logoObj.GetMediaType().ShouldBe(SvgQRCode.SvgLogo.MediaType.PNG);
+
+ var svg = new SvgQRCode(data).GetGraphic(10, Color.DarkGray, Color.White, logo: logoObj);
+
+ var result = HelperFunctions.StringToHash(svg);
+ result.ShouldBe("7d53f25af04e52b20550deb2e3589e96");
+ }
+
[Fact]
[Category("QRRenderer/SvgQRCode")]
public void can_render_svg_qrcode_with_svg_logo_embedded()