StretchDIBits(g.GetHdc(), 0, 0, 512, 512, 0, 0, 512, 512, pt, bm, DIB_RGB_COLORS, SRCCOPY);
別人寫的
public void DrawImage(byte[] pixels, Graphics g)
{
// Create a BITMAPINFO object representing the image to be drawn
// Image is 512 x 512, 8bpp
BITMAPINFO bmi = new BITMAPINFO();
bmi.biWidth = 512;
bmi.biHeight = 512;
bmi.biPlanes = 1;
bmi.biBitCount = 8;
bmi.biSizeImage = pixels.Length;
IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BITMAPINFO)));
[color=#FF0000] Marshal.Copy(pixels, 0, pt, Marshal.SizeOf(typeof(BITMAPINFO)));
IntPtr bm = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BITMAPINFO)));[/color] // Draw the image using the graphics object
StretchDIBits(g.GetHdc(), 0, 0, 512, 512, 0, 0, 512, 512, pt, bm, DIB_RGB_COLORS, SRCCOPY);
}