Skip to content

Commit

Permalink
Merge pull request #3 from ping/custom-ecclevel
Browse files Browse the repository at this point in the history
feat: Support custom ECC Level
  • Loading branch information
guitarrapc authored Mar 5, 2020
2 parents 2152915 + a1b4c62 commit 8f2edfe
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/SkiaSharp.QrCode/Image/QrCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public QrCode(string content, Vector2Slim qrSize, SKEncodedImageFormat outputFor
/// Generate QR Code and output to stream
/// </summary>
/// <param name="outputImage"></param>
public void GenerateImage(Stream outputImage, bool resetStreamPosition = true)
public void GenerateImage(Stream outputImage, bool resetStreamPosition = true, ECCLevel eccLevel = ECCLevel.L)
{
if (outputImage.CanSeek && resetStreamPosition)
outputImage.Seek(0, SeekOrigin.Begin);

if (outputImage.CanSeek && resetStreamPosition)
outputImage.Seek(0, SeekOrigin.Begin);

using (var generator = new QRCodeGenerator())
{
var qr = generator.CreateQrCode(content, ECCLevel.L);
var qr = generator.CreateQrCode(content, eccLevel);

using (var qrSurface = SKSurface.Create(qrInfo))
{
Expand All @@ -49,16 +49,16 @@ public void GenerateImage(Stream outputImage, bool resetStreamPosition = true)
/// <param name="baseImage"></param>
/// <param name="baseQrSize"></param>
/// <param name="qrPosition"></param>
public void GenerateImage(Stream outputImage, Stream baseImage, Vector2Slim baseQrSize, Vector2Slim qrPosition, bool resetStreamPosition = true)
public void GenerateImage(Stream outputImage, Stream baseImage, Vector2Slim baseQrSize, Vector2Slim qrPosition, bool resetStreamPosition = true, ECCLevel eccLevel = ECCLevel.L)
{
if (outputImage.CanSeek && resetStreamPosition)
outputImage.Seek(0, SeekOrigin.Begin);
if (baseImage.CanSeek && resetStreamPosition)
baseImage.Seek(0, SeekOrigin.Begin);

if (outputImage.CanSeek && resetStreamPosition)
outputImage.Seek(0, SeekOrigin.Begin);
if (baseImage.CanSeek && resetStreamPosition)
baseImage.Seek(0, SeekOrigin.Begin);

using (var generator = new QRCodeGenerator())
{
var qr = generator.CreateQrCode(content, ECCLevel.L);
var qr = generator.CreateQrCode(content, eccLevel);

using (var qrSurface = SKSurface.Create(qrInfo))
{
Expand All @@ -79,14 +79,14 @@ public void GenerateImage(Stream outputImage, Stream baseImage, Vector2Slim base
/// <param name="baseImage"></param>
/// <param name="baseQrSize"></param>
/// <param name="qrPosition"></param>
public void GenerateImage(Stream outputImage, byte[] baseImage, Vector2Slim baseQrSize, Vector2Slim qrPosition, bool resetStreamPosition = true)
public void GenerateImage(Stream outputImage, byte[] baseImage, Vector2Slim baseQrSize, Vector2Slim qrPosition, bool resetStreamPosition = true, ECCLevel eccLevel = ECCLevel.L)
{
if (outputImage.CanSeek && resetStreamPosition)
outputImage.Seek(0, SeekOrigin.Begin);

if (outputImage.CanSeek && resetStreamPosition)
outputImage.Seek(0, SeekOrigin.Begin);

using (var generator = new QRCodeGenerator())
{
var qr = generator.CreateQrCode(content, ECCLevel.L);
var qr = generator.CreateQrCode(content, eccLevel);

using (var qrSurface = SKSurface.Create(qrInfo))
{
Expand All @@ -110,7 +110,7 @@ private void Save(SKImage qrImage, Stream outputImage)
}

private void SaveCombinedImage(SKImage qrImage, Stream baseImage, Vector2Slim baseImageSize, Vector2Slim qrPosition, Stream output)
{
{
var baseInfo = new SKImageInfo(baseImageSize.X, baseImageSize.Y);
using (var baseSurface = SKSurface.Create(baseInfo))
using (SKBitmap baseBitmap = SKBitmap.Decode(baseImage))
Expand Down

0 comments on commit 8f2edfe

Please sign in to comment.