codebude / QRCoder

A pure C# Open Source QR Code implementation
MIT License
4.46k stars 1.09k forks source link

not working on ASP.NET Core #66

Closed wendt88 closed 7 years ago

wendt88 commented 7 years ago

hi, is it possible, that this libraray isn't working on ASP.NET Core applications? I have installed it via NuGet and there are missing some classes. Ican create the qrCodeData, but there is no class to work with it (Base64QRCode etc)

codebude commented 7 years ago

Hi @wendt88 ,

the NuGet package contains three different binaries. They differ in their target frameworks.

There is...

Since most of the renderer classes like "QrCode", "Base64QrCode", etc. rely on Graphical methods which are only available in the full framework (.NET 4.0, etc.), those classes are missing in the PCL version. Let me quote the following part from the readme:

Besides the normal QRCode class (which is shown in the example above) for creating QR codes in Bitmap format, there are some more QR code rendering classes, each for another special purpose.

  • QRCode*
  • Base64QRCode*
  • BitmapByteQRCode
  • SvgQRCode*
  • UnityQRCode*

(*) - Those classes are only available in the .NET Framework version. If you use the PCL version (e.g. for Universal apps), you have to use BitmapByteQRCode.

Since ASP.NET Core isn't a full .NET framework installation, the Nuget Package Manager automatically takes the PCL version.

This means, that you have two options:

  1. Use the BitmapByteQRCode-class. It gives you an byte[] which contains the QrCode as Bitmap. You could than create a "Graphic", "Bitmap", whatsoever object or ceate a Base64 string from the byte[]
  2. Use the QrCodeData's "DataMatrix" which is an array of bools which represent the black and white blocks of a QrCode. With this information you could write your own renderer.

Why aren't the other QrCode-renderers part of the PCL version?

Initially I wrote QrCoder for full .NET framework stack. Due to multiple requests the PCL version was added with the aim to target as most platforms as possible. So the PCL version can be used on Android devices, in .NET core, Windows Phone, etc. All of these target platforms have different implementations of Bitmap and Graphics classes. For this reason I'm unable to add the renderers, because I had to focus on a subset of functions which is share around all the platforms. And this was, until now, the byte[] containing the Bitmap data.

If you have some creative ideas, to bring the PCL library version to a new level, feel free to discuss them with the community or bring in your pull request.

qazq commented 7 years ago

Hi @codebude ,

How about this library? https://github.com/CoreCompat/CoreCompat Is it possible to use this library to make QRCoder supports Bitmap and Graphics?

codebude commented 7 years ago

Hi @qazq this would be an option to think about. Until now QrCoder comes as a single DLL solution without any dependencies. This benefit would get lost by using an external dependency. But let me think about it...

tilkinsc commented 7 years ago

I personally think users should get a bitmap in memory and let the user connect up what they want. This QR code generator should be small.

codebude commented 7 years ago

@Hydroque so you prefer to keep the current solution?

tilkinsc commented 7 years ago

Yes. Sorry for brevity. Was on phone. I would think that an extra class for it is a little bit overkill, as all that in necessary is a function that returns data in one go. Perhaps some shrinking is in order, but I haven't taken a full look at all the features this library has yet.