ClassLibraryWeiBao/QR二维码/Windows/Render/WriteableBitmapRenderer.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.IO;

namespace Gma.QrCodeNet.Encoding.Windows.Render
{
    public class WriteableBitmapRenderer
    {
        public Color DarkColor { get; set; }
        public Color LightColor { get; set; }

        public ISizeCalculation ISize { get; set; }

        /// <summary>
        /// Initialize renderer
        /// </summary>
        /// <param name="iSize">Size calculation strategy</param>
        public WriteableBitmapRenderer(ISizeCalculation iSize)
            : this(iSize, Colors.Black, Colors.White)
        { }

        /// <summary>
        /// Initialize renderer
        /// </summary>
        /// <param name="iSize">Size calculation strategy</param>
        /// <param name="darkColor">Color for dark module</param>
        /// <param name="lightColor">Color for light module</param>
        public WriteableBitmapRenderer(ISizeCalculation iSize, Color darkColor, Color lightColor)
        {
            this.LightColor = lightColor;
            this.DarkColor = darkColor;
            this.ISize = iSize;
        }

        /// <summary>
        /// Draw QrCode at given writeable bitmap
        /// </summary>
        public void Draw(WriteableBitmap wBitmap, BitMatrix matrix)
        {
            this.Draw(wBitmap, matrix, 0, 0);
        }

        /// <summary>
        /// Draw QrCode at given writeable bitmap at offset location
        /// </summary>
        public void Draw(WriteableBitmap wBitmap, BitMatrix matrix, int offsetX, int offsetY)
        {
            DrawingSize size = matrix == null ? ISize.GetSize(21) : ISize.GetSize(matrix.Width);
            if (wBitmap == null)
                wBitmap = new WriteableBitmap(size.CodeWidth + offsetX, size.CodeWidth + offsetY, 96, 96, PixelFormats.Gray8, null);
            else if (wBitmap.PixelHeight == 0 || wBitmap.PixelWidth == 0)
                return; //writeablebitmap contains no pixel.
            this.DrawQuietZone(wBitmap, size.CodeWidth, offsetX, offsetY);
            if (matrix == null)
                return;

            this.DrawDarkModule(wBitmap, matrix, offsetX, offsetY);
        }
后面还有 85 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。