ClassLibraryWeiBao/QR二维码/Windows/Render/WriteableBitmapExtension.cs
(开头部分) 6KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Runtime.InteropServices;
namespace Gma.QrCodeNet.Encoding.Windows.Render
{
internal static class WriteableBitmapExtension
{
/// <summary>
/// Clear all pixel with given color.
/// </summary>
/// <param name="wBitmap">Must not be null, or pixel width, pixel height equal to zero</param>
/// <exception>Exception should be expect with null writeablebitmap or pixel width, height equal to zero.</exception>
internal static void Clear(this WriteableBitmap wBitmap, Color color)
{
if (!(wBitmap.Format == PixelFormats.Pbgra32 || wBitmap.Format == PixelFormats.Gray8))
return;
byte[] col = ConvertColor(wBitmap.Format, color);
//Currently only support two PixelFormat.
int sizeOfColor = wBitmap.Format == PixelFormats.Pbgra32 ? 4 : 1;
int pixelW = wBitmap.Format == PixelFormats.Gray8 ? wBitmap.BackBufferStride : wBitmap.PixelWidth;
int pixelH = wBitmap.PixelHeight;
int totalPixels = pixelW * pixelH;
wBitmap.Lock();
unsafe
{
byte* pixels = (byte*)wBitmap.BackBuffer;
int length = col.Length;
//Draw first dot color.
for (int index = 0; index < length; index++)
{
*(pixels + index) = col[index];
}
int pixelIndex = 1;
int blockPixels = 1;
//Expand to all other pixels with Log(n) process.
while (pixelIndex < totalPixels)
{
CopyUnmanagedMemory(pixels, 0, pixels, pixelIndex * sizeOfColor, blockPixels * sizeOfColor);
pixelIndex += blockPixels;
blockPixels = Math.Min(2 * blockPixels, totalPixels - pixelIndex);
}
}
wBitmap.AddDirtyRect(new Int32Rect(0, 0, wBitmap.PixelWidth, wBitmap.PixelHeight));
wBitmap.Unlock();
}
/// <summary>
/// Draw rectangle with given color.
/// </summary>
/// <param name="wBitmap">Must not be null, or pixel width, pixel height equal to zero</param>
/// <exception>Exception should be expect with null writeablebitmap or pixel width, height equal to zero.</exception>
后面还有 113 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。