111,097
社区成员




小狗
╭╮ ╭╮
││ ││
╭┴┴———————┴┴╮
│ │
│ │
│ ● ● │
│○ ╰┬┬┬╯ ○│
│ ╰—╯ │
╰——┬O———O┬——╯
╭╮ ╭╮
╰┴————┴╯
陪你看日出
﹎ ┈ ┈ .o┈ ﹎ ﹎.. ○
﹎┈﹎ ● ○ .﹎ ﹎o▂▃▅▆
┈ ┈ /█\/▓\ ﹎ ┈ ﹎﹎ ┈ ﹎
▅▆▇█████▇▆▅▃▂┈﹎
SNOOPY
.----.
_.'__ `.
.--(#)(##)---/#\
.' @ /###\
: , #####
`-..__.-' _.-\###/
`;_: `"'
.'"""""`.
/, 野比 ,\
// 很穷! \\
`-._______.-'
___`. | .'___
(______|______)
public static string Generate(Bitmap img, int rowSz, int colSz)
{
StringBuilder sb
= new StringBuilder(
img.Width / colSz * img.Height / rowSz
);
FastBitmap fast
= new FastBitmap(
img
);
fast.Lock();
for (int h = 0; h < img.Height / rowSz; h++)
{
int yoffset = h * rowSz;
for (int w = 0; w < img.Width / colSz; w++)
{
int xoffset = w * colSz;
int br = 0;
for (int y = 0; y < 10; y++)
for (int x = 0; x < 10; x++)
try
{
Color c = fast.GetPixel(
x + xoffset,
y + yoffset);
br =
br + (int)(c.GetBrightness() * 10);
}
catch
br += 10;
br /= 10;
if (br / 5 < charset.Length)
sb.Append(
charset[br / 5]);
else
sb.Append(' ');
}
sb.AppendLine();
}
fast.Unlock();
return sb.ToString();
}
unsafe public void SetPixel(int x, int y, Color c)
{
if (_bitmapData.PixelFormat == PixelFormat.Format32bppArgb)
{
byte* b = (byte*)_bitmapData.Scan0 + (y * _bitmapData.Stride) + (x * 4);
*b = c.B;
*(b + 1) = c.G;
*(b + 2) = c.R;
*(b + 3) = c.A;
}
if (_bitmapData.PixelFormat == PixelFormat.Format24bppRgb)
{
byte* b = (byte*)_bitmapData.Scan0 + (y * _bitmapData.Stride) + (x * 3);
*b = c.B;
*(b + 1) = c.G;
*(b + 2) = c.R;
}
}