如题。
我要为Bitmap的一个对象dstImage赋值,所以用了unsafe语句,
例如24位图像的:
byte * p = (byte *)(void *)Scan0;
for(int j=0;j<dstImage.Height;j++)
{
for(int i=0;i<dstImage.Width;i++)
{
sc = srcImage.GetPixel(i,j);
p[0] = (byte)sc.B;
++p;
p[0] = (byte)sc.G;
++p;
p[0] = (byte)sc.R;
++p;
}
p+=nOffset;
}
实现倒是能实现,但是为什么速度这么慢呢?
我要为Bitmap的一个对象dstImage赋值,所以用了unsafe语句,
例如24位图像的:
byte * p = (byte *)(void *)Scan0;
for(int j=0;j<dstImage.Height;j++)
{
for(int i=0;i<dstImage.Width;i++)
{
sc = srcImage.GetPixel(i,j);
p[0] = (byte)sc.B;
++p;
p[0] = (byte)sc.G;
++p;
p[0] = (byte)sc.R;
++p;
}
p+=nOffset;
}
实现倒是能实现,但是为什么速度这么慢呢?
主要是for(int j=0;j<dstImage.Height;j++)这里,应该把dstImage.Height赋为一个值,int h = dstImage.Height;
之后写for(int j=0;j<h;j++)就很快了,将近提高了90%,惊人~!