SHOW:
|
|
- or go back to the newest paste.
1 | using System; | |
2 | using System.Drawing; | |
3 | using System.IO; | |
4 | ||
5 | namespace ImageProcessing | |
6 | { | |
7 | internal class Program | |
8 | { | |
9 | // Path to the input and output image files | |
10 | // The file should be located where the .exe application is | |
11 | public static string imagePath = "image.jpg"; | |
12 | public static string newImagePath = "newImage.jpg"; | |
13 | ||
14 | public static void Main(string[] args) | |
15 | { | |
16 | ||
17 | } | |
18 | ||
19 | public static void BrightenImage(Bitmap img) | |
20 | { | |
21 | ||
22 | } | |
23 | ||
24 | public static void DarkenImage(Bitmap img) | |
25 | { | |
26 | ||
27 | } | |
28 | ||
29 | public static void SwapColors(Bitmap img) | |
30 | { | |
31 | ||
32 | ||
33 | } | |
34 | ||
35 | // This method converts the RGB values entered by the user into a Color object. | |
36 | public static Color ConvertStringToColor(string rgb) | |
37 | { | |
38 | int r, g, b; | |
39 | ||
40 | try | |
41 | { | |
42 | string[] rgbComponents = rgb.Split(','); | |
43 | r = int.Parse(rgbComponents[0]); | |
44 | g = int.Parse(rgbComponents[1]); | |
45 | b = int.Parse(rgbComponents[2]); | |
46 | return Color.FromArgb(r, g, b); | |
47 | } | |
48 | catch (Exception e) | |
49 | { | |
50 | Console.WriteLine("Invalid color input. Setting default color (black)."); | |
51 | return Color.Black; | |
52 | } | |
53 | } | |
54 | ||
55 | // This method prevents values from exceeding the 0-255 (RGB) range by clamping the variables. | |
56 | public static int ClampValue(int value) | |
57 | { | |
58 | if (value < 0) return 0; | |
59 | if (value > 255) return 255; | |
60 | ||
61 | return value; | |
62 | } | |
63 | ||
64 | // This method retrieves the image from the given path and displays a message if there's a problem. | |
65 | public static Bitmap LoadImage(string filePath) | |
66 | { | |
67 | if (File.Exists(filePath) == false) return null; | |
68 | ||
69 | try | |
70 | { | |
71 | Bitmap bitmap = new Bitmap(filePath); | |
72 | return bitmap; | |
73 | } | |
74 | catch (Exception e) | |
75 | { | |
76 | Console.WriteLine(e); | |
77 | return null; | |
78 | } | |
79 | } | |
80 | } | |
81 | } | |
82 |