-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support passing PNG data directly to SvgLogo #491
Changes from 1 commit
b8654c6
42132c6
a8277be
4b8fafd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,7 @@ public void can_render_svg_qrcode_without_quietzones_hex() | |
|
||
[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(); | ||
|
@@ -119,7 +119,26 @@ 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("7d53f25af04e52b20550deb2e3589e96"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the extra padding was removed from the SVG, the hash has changed. |
||
} | ||
|
||
[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>(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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can see here that the new constructor results in the same hash as using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this is false. Well, I was sorta surprised; .NET should re-encode the PNG with the Bitmap constructor. Not sure why I thought otherwise. |
||
} | ||
|
||
[Fact] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetBuffer()
returns the current working memory buffer allocated byMemoryStream
, including extra padding that is reserved but not yet used by theMemoryStream
. This is unlikeToArray
which copies the working data to a new array of the correct length. To properly useGetBuffer
, the length must be passed toConvert.ToBase64String
so that only the working data is encoded.