forked from xiaoyaocz/biliuwp-lite
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
124 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using BiliLite.Services; | ||
using BiliLite.Services.Interfaces; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace BiliLite.Extensions | ||
{ | ||
public static class QrCodeExtensions | ||
{ | ||
public static IServiceCollection AddQrCodeService(this IServiceCollection services) | ||
{ | ||
#if ARM64 | ||
services.AddTransient<IQrCodeService, QrCoderQrCodeService>(); | ||
#else | ||
services.AddTransient<IQrCodeService, ZXingQrCodeService>(); | ||
#endif | ||
return services; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Threading.Tasks; | ||
using Windows.UI.Xaml.Media; | ||
|
||
namespace BiliLite.Services.Interfaces | ||
{ | ||
public interface IQrCodeService | ||
{ | ||
public Task<ImageSource> GenerateQrCode(string content, int size = 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Windows.UI.Xaml.Media; | ||
using BiliLite.Services.Interfaces; | ||
using QRCoder; | ||
using Windows.Storage.Streams; | ||
using Windows.UI.Xaml.Media.Imaging; | ||
|
||
namespace BiliLite.Services | ||
{ | ||
public class QrCoderQrCodeService : IQrCodeService | ||
{ | ||
public async Task<ImageSource> GenerateQrCode(string content, int size = 200) | ||
{ | ||
var qrGenerator = new QRCodeGenerator(); | ||
var qrCodeData = qrGenerator.CreateQrCode(content, QRCodeGenerator.ECCLevel.Q); | ||
|
||
var qrCodeBmp = new BitmapByteQRCode(qrCodeData); | ||
var qrCodeImageBmp = qrCodeBmp.GetGraphic(size); | ||
|
||
using var stream = new InMemoryRandomAccessStream(); | ||
using var writer = new DataWriter(stream.GetOutputStreamAt(0)); | ||
writer.WriteBytes(qrCodeImageBmp); | ||
await writer.StoreAsync(); | ||
var image = new BitmapImage(); | ||
await image.SetSourceAsync(stream); | ||
return image; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Threading.Tasks; | ||
using Windows.UI.Xaml.Media; | ||
using BiliLite.Services.Interfaces; | ||
|
||
namespace BiliLite.Services | ||
{ | ||
public class ZXingQrCodeService : IQrCodeService | ||
{ | ||
public Task<ImageSource> GenerateQrCode(string content,int size=200) | ||
{ | ||
var barcodeWriter = new ZXing.BarcodeWriter | ||
{ | ||
Format = ZXing.BarcodeFormat.QR_CODE, | ||
Options = new ZXing.Common.EncodingOptions() | ||
{ | ||
Margin = 1, | ||
Height = size, | ||
Width = size | ||
} | ||
}; | ||
var img = barcodeWriter.Write(content); | ||
return Task.FromResult<ImageSource>(img); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters