Skip to content

Instantly share code, notes, and snippets.

@lxrite

lxrite/Alipay.cs Secret

Last active December 24, 2016 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lxrite/d07f752c863c4d356fabfd7f4b3136c0 to your computer and use it in GitHub Desktop.
Save lxrite/d07f752c863c4d356fabfd7f4b3136c0 to your computer and use it in GitHub Desktop.
AR Red Envelope
// 自用的代码,不同机型可能需要修改偏移
private void FixRange(Bitmap bitmap, int y1, int y2)
{
int top = (y2 - y1) / 2 + (y2 - y1) % 2;
int bottom = (y2 - y1) - top;
for (int y = y1; y <= y1 + top; ++y)
{
for (int x = 205; x < 205 + 340; ++x)
{
int targety = y - top;
var pixel = bitmap.GetPixel(x, targety);
bitmap.SetPixel(x, y, pixel);
}
}
for (int y = y2; y > y1 + top - ((y2 - y1) % 2); --y)
{
for (int x = 205; x < 205 + 340; ++x)
{
int targety = y + bottom;
var pixel = bitmap.GetPixel(x, targety);
bitmap.SetPixel(x, y, pixel);
}
}
}
private void FillWhite(Bitmap bitmap)
{
for (int x = 0; x < bitmap.Width; ++x)
{
for (int y = 0; y < 638; ++y)
{
bitmap.SetPixel(x, y, Color.White);
}
for (int y = 638 + 340; y < bitmap.Height; ++y)
{
bitmap.SetPixel(x, y, Color.White);
}
}
for (int y = 638; y < 638 + 340; ++y)
{
for (int x = 0; x < 205; ++x)
{
bitmap.SetPixel(x, y, Color.White);
}
for (int x = 205 + 340; x < bitmap.Width; ++x)
{
bitmap.SetPixel(x, y, Color.White);
}
}
}
private void button_Click(object sender, EventArgs e)
{
using (Bitmap bitmap = (Bitmap)Bitmap.FromFile(@"D:\bmp\input.bmp", false))
{
if (bitmap.Width != 750 || bitmap.Height != 1334)
{
return;
}
FillWhite(bitmap);
int end = 638 + 2;
int count = 0;
while (true)
{
++count;
int begin = end + 7;
if (count % 7 == 0)
{
++begin;
}
end = begin + 5;
if (end >= 638 + 340)
{
break;
}
FixRange(bitmap, begin, end);
}
bitmap.Save(@"D:\bmp\output.bmp");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment