且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在c#中使用Windows控制台应用程序显示图像

更新时间:2022-10-18 14:28:41

您无法在 控制台窗口中显示位图/图像 :控制台仅限文本。这里有一个很好的总结,你可以和控制台窗口无法做到:[ ^ ]。



你可以这样做:



0.参考System.Drawing在控制台应用程序中,创建图形,并将它们保存到文件,或打开grahics文件并修改其位并保存,等等。



1.显示控制台窗口中的Unicode扩展字符,其中一些是图形类型



2.让自己疯狂尝试制作角色艺术



3.在Windows窗体应用程序中或与Windows窗体应用程序一起显示控制台窗口,并使用WinForm应用程序以通常的方式显示位图/图像。



我在2009年使用***上的这篇文章中的代码进行了探索:[ ^ ]。



我问了一个基于我的经验的问题适应该代码:[ ^ ]。



原来是棘手的东西,让Window和Console一起工作,定位正确等等


你可以创建一个窗体并将其边框设置为无添加图片框设置其底座填充并设置其图像然后显示表格



这里是代码:

  var  f =  new  Form(); 
f.FormBorderStyle = FormBorderStyle.None;
f.Controls.Add( new PictureBox(){ImageLocation = @ Path // To // Image,Dock = DockStyle.Fill});
f.Show();



希望它适合你。



编辑:

不要使用命名空间System.Windows.Forms

 使用 System.Windows.Forms; 


hi,

Please help me out, how to display image using windows console application in c#.

is it possible?

You cannot display a bitmap/image in a Console Window: the Console is Text only. Good summary here of what you can, and can't do with a Console Window: [^].

You can do this:

0. reference System.Drawing in a Console app, and create graphics, and save them to a file, or open a grahics file and modify its bits and save it, etc.

1. display Unicode extended characters in the Console Window, some of which are kind-of graphics

2. drive yourself crazy trying to make art of characters

3. display a Console Window in, or along with, a Windows Forms application, and use the WinForm app to display the bitmap/image in the usual way.

I explored this in 2009, using code on this post on ***: [^].

And I asked a question based on my experience adapting that code: [^].

Turned out to be tricky stuff, getting the Window and Console working together, positioned correctly, etc.


Well you can create a windows form and set its border to none add a picture box set its dock to fill and set its image then show the form

here is the code:
var f = new Form();
f.FormBorderStyle = FormBorderStyle.None;
 f.Controls.Add(new PictureBox() { ImageLocation = @"Path//To//Image",Dock = DockStyle.Fill});
f.Show();


Hope it works for you.

EDIT:
dont for get to use the namespace System.Windows.Forms

using System.Windows.Forms;