古詩詞大全網 - 四字成語 - c#中調用函數StretchDIBits的參數問題,函數功能涉及圖像處理顯示

c#中調用函數StretchDIBits的參數問題,函數功能涉及圖像處理顯示

Graphics g

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);

}