Display a Image in a console application

后端 未结 7 1928
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 10:06

I have a console application that manages images. Now i need something like a preview of the Images within the console application. Is there a way to display them in the con

相关标签:
7条回答
  • 2020-11-27 10:40

    Yes, you can do it, if you stretch the question a little by opening a Form from within the Console application.

    Here is how you can have you console application open a form and display an image:

    • include these two references in your project: System.Drawing and System.Windows.Forms
    • include the two namespaces as well:

    using System.Windows.Forms;
    using System.Drawing;
    

    See this post on how to do that!

    Now all you need it to add something like this:

    Form form1 = new Form();
    form1.BackgroundImage = bmp;
    form1.ShowDialog();
    

    Of course you can also use a PictureBox..

    And you can use form1.Show(); to keep the console alive while the preview shows..

    Original post: Of course you can't properly display an image inside a 25x80 window; even if you use a larger window and block graphics it wouldn't be a preview but a mess!

    Update: Looks like you can after all GDI-draw an image onto the Console Form; see taffer's answer!

    0 讨论(0)
提交回复
热议问题