0

I'm trying to open an image in C# based on user defined strings. What I have is the main program which asks the following from the user.

Console.WriteLine("Please input the type of genre you wish to test: Western, Action, Thriller or Comedy");
inputGenre = Console.ReadLine();
List<string> resultantShots = Film.outputShots(inputGenre, trainFilms);
Console.WriteLine("Final shot sequence should therefore follow this guideline: ");
resultantShots.ForEach(Console.WriteLine);
Film.imageOutput(inputGenre, resultantShots[0]);

This will ask the user to input a specific string, then generate a list of strings afterwards in a static function (which already works and generates the output I want) The final line points to another static function which currently looks like this:

public static void imageOutput(string genre, string shot)
{
    bool contains = Directory.EnumerateFiles(genre).Any(f => f.Contains(shot));
    if (contains)
    {
        Console.WriteLine("Genre found");
    }
}

This function will take the user input string, check if the string matches the name of a folder in the directory "bin/Debug/net 6.0" and then afterwards check if a film contains the string. My current issue is this: In each folder I have images that will match a string from the resultant shot list. For example, the resultant shot might be a string "Medium Full" and I have a png image called Medium Full. I'm just unsure however, on how I open this image in the console itself. Equally, I want to only open images that exactly match the string itself. If the string for instance is "Medium Full" I don't want my program to open an image labelled "medium".

I've never really worked with images before in C#, so if anyone has any advice it would be appreciated.

Palle Due
  • 5,929
  • 4
  • 17
  • 32
  • 4
    You need to define what "open an image" mean to you. – Franck Feb 20 '23 at 13:40
  • You cannot display an image in a console app. You can use the console app to open the image in a graphics app. Or you can create, for instance, a Windows Forms app and display the image in a picture box. – Olivier Jacot-Descombes Feb 20 '23 at 13:53
  • Sorry, I'll be a bit more clear. When I say open an image, I just need it to be displayed on the screen. However it seems that I may need to look at using a graphics app/ windows form app, which is a little new to me. Any tutorials you know of that might help? – RadioCode345 Feb 20 '23 at 14:24
  • Does this help answer your question? https://stackoverflow.com/a/33652557/5438626 – IVSoftware Feb 20 '23 at 14:56
  • That said, since you're doing something graphical you may be more on the right track when you mention something like a "windows forms app" https://learn.microsoft.com/en-us/dotnet/desktop/winforms/ – IVSoftware Feb 20 '23 at 15:01
  • I am currently trying to use a package now called SkiaSharp, which I believe I can use to render the png file that I want to display, however so far I haven't had any luck either, I can display what I have in a new comment if needed. – RadioCode345 Feb 20 '23 at 15:03
  • Also, there are two questions here: **how I open this image in the console itself** and **equally, I want to only open images that exactly match the string itself**. It might draw more useful answers if you divided this into two questions with better focus because one is about string queries and the other about graphical display - really quite different in nature. – IVSoftware Feb 20 '23 at 15:12
  • Understood. I think I now have an idea on the second part of the question, though I am getting stuck on the first part still. I might make a new question later just asking the first part if it's going to be a bit clearer to answer. Thanks for the advice. – RadioCode345 Feb 20 '23 at 15:14
  • See: [C# Windows Forms Application Tutorial with Example](https://www.guru99.com/c-sharp-windows-forms-application.html) – Olivier Jacot-Descombes Feb 20 '23 at 15:20
  • One thing I should check before attempting to make this a form, I plan to have it so that the list is iterated through and will display a different image each time based on what each string is. Is this still possible via a form. – RadioCode345 Feb 20 '23 at 15:37
  • Yes, you can store the images (or their file names) in a list or array either use buttons to navigate through the list or use a ListBox for the selection (just as an example). – Olivier Jacot-Descombes Feb 20 '23 at 15:49
  • Before you start creating a GUI app, try [opening the file with the default image app](https://stackoverflow.com/questions/11365984/) from the console. – Corvus Feb 20 '23 at 15:59

0 Answers0