/// <summary>
/// 积木实现方法
/// </summary>
private void Image_Block()
{
if (this.pbshowbox.Image != null)
{
int Height = this.pbshowbox.Image.Height;
int Width = this.pbshowbox.Image.Width;
Bitmap bitmap = new Bitmap(Width, Height);
Bitmap Mybitmap = (Bitmap)this.pbshowbox.Image;
BitmapData oldData = Mybitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
BitmapData newData = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
unsafe
{
byte* pin = (byte*)(oldData.Scan0.ToPointer());
byte* pout = (byte*)(newData.Scan0.ToPointer());
for (int y = 0; y < oldData.Height; y++)
{
for (int x = 0; x < oldData.Width; x++)
{
int avg = (pin[0] + pin[1] + pin[2]) / 3;
if (avg > 128)
{
pout[0] = 255;
pout[1] = 255;
pout[2] = 255;
}
else
{
pout[0] = 0;
pout[1] = 0;
pout[2] = 0;
}
pin = pin + 3;
pout = pout + 3;
}
pin = pin + oldData.Stride - oldData.Width * 3;
pout = pout + newData.Stride - newData.Width * 3;
}
bitmap.UnlockBits(newData);
Mybitmap.UnlockBits(oldData);
this.pbshowbox.Image = bitmap;
C# 内存法图像处理(6)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/e9faf41fde605cb925e0bf8689e9c327.html