if (r < 0) r = 0;
if (r > 255) r = 255;
if (g < 0) g = 0;
if (g > 255) g = 255;
if (b < 0) b = 0;
if (b > 255) b = 255;
pout[0] = (byte)(b);
pout[1] = (byte)(g);
pout[2] = (byte)(r);
pin_1 = pin_1 + 3;
pin_2 = pin_2 + 3;
pout = pout + 3;
}
pin_1 += oldData.Stride - oldData.Width * 3;
pin_2 += oldData.Stride - oldData.Width * 3;
pout += newData.Stride - newData.Width * 3;
}
bitmap.UnlockBits(newData);
MyBitmap.UnlockBits(oldData);
this.pbshowbox.Image = bitmap;
}
}
else
{
MessageBox.Show("请先打开一张图片!");
}
}
五、底片
颜色值取反。
/// <summary>
/// 底片实现方法
/// </summary>
void Image_Negative()
{
if (pbshowbox.Image != null)
{
int Height = this.pbshowbox.Image.Height;
int Width = this.pbshowbox.Image.Width;
Bitmap bitmap = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
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++)
{
pout[0] = (byte)(255 - pin[0]);
pout[1] = (byte)(255 - pin[1]);
pout[2] = (byte)(255 - pin[2]);
pin = pin + 3;
pout = pout + 3;
}
pin += oldData.Stride - oldData.Width * 3;
pout += newData.Stride - newData.Width * 3;
}
bitmap.UnlockBits(newData);
MyBitmap.UnlockBits(oldData);
this.pbshowbox.Image = bitmap;
}
}
else
{
MessageBox.Show("请先打开一张图片!");
}
}
六、积木
低像素置0,高像素置255。