由于做C#控制台程序,并需要实时显示AI渲染结果进行调试。
下面代码直接在控制台的程序中调用ShowPictrues(图像byte[])就可以了
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr GetConsoleWindow();
private static void ShowPictures(byte[] imgData)
{
Graphics g = Graphics.FromHwnd(GetConsoleWindow());
{
using (Image image = Image.FromStream(new MemoryStream(imgData)))
{
Rectangle rect = new Rectangle(0, 0, 500, 400);
g.DrawImage(image, rect);
}
}
}