-
-
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
Cannot use 5 argument version of QRCode constructor under Windows .net 8.0 with Nuget 1.5.1 #536
Comments
When talking about QrCode constructor you mean the constructor of the QrCode renderer class? If so, this has no overload with 5 arguments. Please check the wiki: https://github.com/codebude/QRCoder/wiki/Advanced-usage---QR-Code-renderers#21-qrcode-renderer-in-detail To give you a more detailed answer it would be helpful if you could post a short snippet of your code that throws the error. |
Overload version 4 - the params after #5 are defaults. Anyway only 2
versions of the constructor signature exist. I solved the problem using
ImageSharp to merge the logo with QRCode. For those similarly situated
this was my solution. Thanks to chatgpt for providing 1bit to
32bit conversion code.
byte[] qrCodeImage = qrCode.GetGraphic(20);
Image<Rgba32> qrImage =
SixLabors.ImageSharp.Image.Load<Rgba32>(ConvertTo32Bit(qrCodeImage));
Image<Rgba32> logo =
SixLabors.ImageSharp.Image.Load<Rgba32>("logo.png");
int x = (qrImage.Width - logo.Width) / 2;
int y = (qrImage.Height - logo.Height) / 2;
qrImage.Mutate(ctx => ctx.DrawImage(logo, new
SixLabors.ImageSharp.Point(x, y), new GraphicsOptions
{
AlphaCompositionMode =
PixelAlphaCompositionMode.SrcOver,
BlendPercentage = 1f
}));
qrImage.Save(@"logo-with-image.png");
static byte[] ConvertTo32Bit(byte[] qrCodeImage)
{
using (var ms = new MemoryStream(qrCodeImage))
{
using (var bitmap = new Bitmap(ms))
{
using (var convertedBitmap = new Bitmap(bitmap.Width,
bitmap.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
using (var graphics =
Graphics.FromImage(convertedBitmap))
{
graphics.DrawImage(bitmap, 0, 0);
}
using (var stream = new MemoryStream())
{
convertedBitmap.Save(stream,
System.Drawing.Imaging.ImageFormat.Png);
return stream.ToArray();
}
}
}
}
}
…On Fri, May 24, 2024 at 5:42 PM Raffael Herrmann ***@***.***> wrote:
When talking about QrCode constructor you mean the constructor of the
QrCode renderer class? If so, this has no overload with 5 arguments. Please
check the wiki:
https://github.com/codebude/QRCoder/wiki/Advanced-usage---QR-Code-renderers#21-qrcode-renderer-in-detail
To give you a more detailed answer it would be helpful if you could post a
short snippet of your code that throws the error.
—
Reply to this email directly, view it on GitHub
<#536 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAUBNHD3Z6YGXLX5CZQDR2DZD6X4ZAVCNFSM6AAAAABIIHRULKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZQGQYDMMRYHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Ok, I re-checked it with a simple test application: QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
var bmp = (Bitmap)Bitmap.FromFile(@"C:\\test.png");
Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.Black, Color.White, bmp, 15);
pictureBox1.BackgroundImageLayout = ImageLayout.Zoom;
pictureBox1.BackgroundImage = qrCodeImage; The application runs perfectly fine: All four overloads are showing up: Enviroment was QRCoder 1.5.1 from Nuget, .NET8 as target framework and Windows as development environment; I can't see a bug here. The problem seems to be in your setup. |
I have the same problem in NET 6. I've created a very simple console application: Program.cs
QRCodeTest.csproj
The error in console is:
|
Change this line as follows:
|
That would make my code platform specific, right? It wasn't before and I would not like it to be... |
The For reference, also see MS docs on |
OK, so using
But could not figure out what would be the equivalent for the color parameters, since now it is a byte array. Can they be obtained from the |
var color = System.Drawing.Color.Red;
var darkColorRgba = new byte[] { color.R, color.G, color.B, color.A }; There could probably be an overload for this added... |
Type of issue
[x] Bug
[ ] Question (e.g. about handling/usage)
[ ] Request for new feature/improvement
Expected Behavior
Should be able to use 5 argument version of constructor
Current Behavior
The 5 argument version of the constructor does not exist in Nuget package v 1.5.1
Possible Solution (optional)
Update the Nuget package with current version of code
Steps to Reproduce (for bugs)
Create a new C# console solution with .NET 8.0
Add QRCode 1.5.1 with Nuget
Try to call the 5 argument version of QRCode constructor to make an QR with an embedded image.
Get compile error
Your Environment
Windows 10
.NET 8.0 Standard
Nuget v 1.5.1
The text was updated successfully, but these errors were encountered: