-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawBitmap.cs
111 lines (73 loc) · 2.31 KB
/
DrawBitmap.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright Eric Chauvin 2018 - 2019.
using System;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
// using System.Windows.Forms;
// using System.Windows;
// https://docs.microsoft.com/en-us/dotnet/framework/winforms/advanced/getting-started-with-graphics-programming
// https://docs.microsoft.com/en-us/dotnet/api/system.drawing?view=netframework-4.7.2
// Bitmap class:
// https://docs.microsoft.com/en-us/dotnet/api/system.drawing.bitmap?view=netframework-4.7.2
// PictureBox class:
// https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.picturebox?view=netframework-4.7.2
// Graphics class:
// https://docs.microsoft.com/en-us/dotnet/api/system.drawing.graphics?view=netframework-4.7.2
namespace ClimateModel
{
class DrawBitmap
{
private MainForm MForm;
private DrawBitmap()
{
}
internal DrawBitmap( MainForm UseForm )
{
MForm = UseForm;
}
private void ShowStatus( string ToShow )
{
if( MForm == null )
return;
MForm.ShowStatus( ToShow );
}
internal void MakeImageFile( string FileName )
{
try
{
using( Bitmap BMap = new Bitmap( FileName, true ))
{
if( BMap == null )
{
ShowStatus( "Bitmap was null." );
return;
}
// Bitmap( int width, int height,
// System.Drawing.Imaging.PixelFormat format );
// Pixel format: Format24bppRgb
ShowStatus( "Loaded the bitmap." );
ShowStatus( "Pixel format: " + BMap.PixelFormat.ToString() );
using( Graphics Graph = Graphics.FromImage( BMap ))
{
if( Graph == null )
{
ShowStatus( "Graphics was null." );
return;
}
// X goes to the right and Y points downward.
// https://docs.microsoft.com/en-us/dotnet/framework/winforms/advanced/lines-curves-and-shapes
Pen MyPen = new Pen( Color.Black, 3 );
Graph.DrawLine( MyPen, 0, 0, 200, 200 );
// Save(Stream, ImageFormat)
string ToFileName = FileName.Replace( ".jpg" , "Test.jpg" );
BMap.Save( ToFileName, ImageFormat.Jpeg );
}
} // The file stays locked until it is disposed.
}
catch( Exception Except )
{
ShowStatus( "Exception in DrawBitmap.LoadImageFile(): " + Except.Message );
}
}
}
}