总结一下,对c#的gdi显示做个对比,从c#图像旋转代码中截取(c++一并带过):
//旋转后放入picturebox2
8位显示旋转图像:...... 24位显示旋转图像:......
byte[] image1 = new byte[outwidth * outheight ]; byte[] image1 = new byte[outwidth * outheight *3];
...... ......
if (x >= 0 && x < 256 && y >= 0 && y < 256) if (x >= 0 && x < 256 && y >= 0 && y < 256)
{ {
int temp = j * outwidth + i; int temp = j * outwidth + i;
image1[temp ] = glob_buffer8[y * 256 + x]; image1[temp * 3] = glob_buffer8[y * 256 + x];
} image1[temp * 3+1] = glob_buffer8[y * 256 + x];
image1[temp * 3+2] = glob_buffer8[y * 256 + x];
}
Bitmap curbmp = new Bitmap(outwidth, Bitmap curbmp = new Bitmap(outwidth,
outheight,PixelFormat.Format8bppIndexed ); outheight,PixelFormat. Format24bppRgb);
System.Drawing.Imaging.ColorPalette cp = curbmp.Palette;
for (int i = 0; i < 256; i++)
{
cp.Entries[i] = Color.FromArgb(255, i, i, i);
}
curbmp.Palette = cp;
BitmapData bmpdataout = curbmp.LockBits( ......
new Rectangl( (0, 0, outwidth, outheight), ......
ImageLockMode.ReadWrite, curbmp.PixelFormat); ......
IntPtr ptr0 = bmpdataout.Scan0;//得到首地址 ......
System.Runtime.InteropServices.Marshal.Copy System.Runtime.InteropServices.Marshal.Copy
(image1, 0, ptr0, outwidth * outheight ); (image1, 0, ptr0, outwidth * outheight*3 );
curbmp.UnlockBits(bmpdataout); ......
pictureBox2.Image = curbmp; ......
/ 32位显示旋转图像:
......
byte[] image1 = new byte[outwidth * outheight*4 ];
......
if (x >= 0 && x < 256 && y >= 0 && y < 256)
{
int temp = j * outwidth + i;
image1[temp * 4] = glob_buffer8[y * 256 + x];
image1[temp * 4 + 1] = glob_buffer8[y * 256 + x];
image1[temp * 4+ 2] = glob_buffer8[y * 256 + x];
image1[temp * 4 + 3] = 255;
}
Bitmap curbmp = new Bitmap(outwidth, outheight, PixelFormat.Format32bppArgb);
BitmapData bmpdataout = curbmp.LockBits(new Rectangle(0, 0, outwidth, outheight), ImageLockMode.ReadWrite,
curbmp.PixelFormat);
IntPtr ptr0 = bmpdataout.Scan0;//得到首地址
System.Runtime.InteropServices.Marshal.Copy(image1, 0, ptr0, outwidth * outheight*4);
curbmp.UnlockBits(bmpdataout);
pictureBox2.Image = curbmp;