C#读写BitMap及颜色相乘

C#读写BitMap及颜色相乘

  private Bitmap ReadBitMapAndMultipy(Bitmap bitmap0)
{
int x1width = bitmap0.Width;
int y1height = bitmap0.Height;
Bitmap image = new Bitmap(x1width, y1height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
int iPixelSize = ; BitmapData bitmapdata = image.LockBits(new
Rectangle(, , x1width, y1height),
ImageLockMode.ReadWrite, image.PixelFormat);
BitmapData bitmapdata0 = bitmap0.LockBits(new
Rectangle(, , x1width, y1height),
ImageLockMode.ReadOnly, image.PixelFormat);
try
{
unsafe
{
for (int y = ; y < y1height; y++)
{
byte* row = (byte*)bitmapdata.Scan0 +
(y * bitmapdata.Stride);
byte* row0 = (byte*)bitmapdata0.Scan0 +
(y * bitmapdata0.Stride);
for (int x = ; x < x1width; x++)
{
byte tempValB = row0[x * iPixelSize];
byte tempValG = row0[x * iPixelSize + ];
byte tempValR = row0[x * iPixelSize + ];
byte tempValA = row0[x * iPixelSize + ];
double r = Convert.ToDouble(tempValR) * / ;
double g = Convert.ToDouble(tempValG) * / ;
double b = Convert.ToDouble(tempValB) * / ; //double r = Convert.ToDouble(tempValR) * 78 / 255;
//double g = Convert.ToDouble(tempValG) * 69 / 255;
//double b = Convert.ToDouble(tempValB) * 48 / 255;
row[x * iPixelSize] = (byte)(b);
row[x * iPixelSize + ] = (byte)(g);
row[x * iPixelSize + ] = (byte)(r);
row[x * iPixelSize + ] = tempValA;
}
} }
}
catch
{
}
finally
{
image.UnlockBits(bitmapdata);
}
return image;
}

ReadBitMapAndMultipy

调用的代码:

 string path = System.IO.Path.GetDirectoryName(fileName);
Image bitmap = pictureBox1.Image;
Bitmap bitmap0 = bitmap as Bitmap;
Bitmap sabe = ReadBitMapAndMultipy(bitmap0);
Guid guid = new Guid();
string file = string.Format(@"{0}\{1}.png", path, guid.ToString());
sabe.Save(file);
上一篇:ie6下使用js替换img标签src属性图片不显示的错误


下一篇:GLFW初体验