-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathBitmap.cs
More file actions
337 lines (293 loc) · 10.2 KB
/
Bitmap.cs
File metadata and controls
337 lines (293 loc) · 10.2 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
using System;
using ScriptEngine.Machine.Contexts;
using ScriptEngine.Machine;
namespace osf
{
public class Bitmap : Image
{
public ClBitmap dll_obj;
public System.Drawing.Bitmap M_Bitmap;
public Bitmap(Image p1)
{
M_Bitmap = new System.Drawing.Bitmap(p1.M_Image);
base.M_Image = M_Bitmap;
OneScriptForms.AddToHashtable(M_Bitmap, this);
}
public Bitmap(Image p1, Size p2)
{
M_Bitmap = new System.Drawing.Bitmap(p1.M_Image, p2.M_Size);
base.M_Image = M_Bitmap;
OneScriptForms.AddToHashtable(M_Bitmap, this);
}
public Bitmap(osf.Bitmap p1)
{
M_Bitmap = p1.M_Bitmap;
base.M_Image = M_Bitmap;
}
public Bitmap(Size p1)
{
M_Bitmap = new System.Drawing.Bitmap(p1.Width, p1.Height);
base.M_Image = M_Bitmap;
OneScriptForms.AddToHashtable(M_Bitmap, this);
}
public Bitmap(Stream p1)
{
M_Bitmap = new System.Drawing.Bitmap(p1.M_Stream);
base.M_Image = M_Bitmap;
OneScriptForms.AddToHashtable(M_Bitmap, this);
}
public Bitmap(string p1)
{
try
{
M_Bitmap = new System.Drawing.Bitmap((System.IO.Stream)new System.IO.MemoryStream(Convert.FromBase64String(p1)));
base.M_Image = M_Bitmap;
}
catch
{
M_Bitmap = new System.Drawing.Bitmap(p1);
base.M_Image = M_Bitmap;
}
OneScriptForms.AddToHashtable(M_Bitmap, this);
}
public Bitmap(System.Drawing.Bitmap p1)
{
M_Bitmap = p1;
base.M_Image = M_Bitmap;
}
public Bitmap(System.Drawing.Image p1)
{
M_Bitmap = new System.Drawing.Bitmap(p1);
base.M_Image = M_Bitmap;
OneScriptForms.AddToHashtable(M_Bitmap, this);
}
public osf.Bitmap Clone(float x, float y, float width, float height)
{
return new Bitmap(M_Bitmap.Clone(
new System.Drawing.Rectangle(
Convert.ToInt32(x),
Convert.ToInt32(y),
Convert.ToInt32(width),
Convert.ToInt32(height)
),
System.Drawing.Imaging.PixelFormat.Undefined)
);
}
public osf.Bitmap FromBase64String(string str)
{
return new Bitmap(new System.Drawing.Bitmap((System.IO.Stream)new System.IO.MemoryStream(Convert.FromBase64String(str))));
}
public osf.Bitmap FromSize(System.Drawing.Size size)
{
return new Bitmap(new System.Drawing.Bitmap(size.Width, size.Height));
}
public osf.ArrayList GetBytes(osf.BitmapData p1)
{
int num = Math.Abs(p1.M_BitmapData.Stride) * M_Bitmap.Height;
byte[] Bytes1 = new byte[num];
System.Runtime.InteropServices.Marshal.Copy(p1.M_BitmapData.Scan0, Bytes1, 0, num);
ArrayList ArrayList1 = new ArrayList();
for (int i = 0; i < num; i++)
{
ArrayList1.Add(System.Convert.ToInt32(Bytes1[i]));
}
return ArrayList1;
}
public osf.Color GetPixel(int p1, int p2)
{
return new Color(M_Bitmap.GetPixel(p1, p2));
}
public osf.BitmapData LockBits()
{
osf.Rectangle Rectangle1 = new Rectangle(0, 0, M_Bitmap.Width, M_Bitmap.Height);
System.Drawing.Imaging.ImageLockMode ImageLockMode1 = System.Drawing.Imaging.ImageLockMode.ReadWrite;
System.Drawing.Imaging.PixelFormat PixelFormat1 = M_Bitmap.PixelFormat;
osf.BitmapData BitmapData1 = new BitmapData(M_Bitmap.LockBits(Rectangle1.M_Rectangle, ImageLockMode1, PixelFormat1));
return BitmapData1;
}
public void MakeTransparent(Color p1)
{
M_Bitmap.MakeTransparent(p1.M_Color);
}
public void SetBytes(osf.BitmapData p1, osf.ArrayList p2)
{
int num = p2.M_ArrayList.Count;
byte[] Bytes1 = new byte[num];
for (int i = 0; i < num; i++)
{
Bytes1[i] = System.Convert.ToByte(p2.M_ArrayList[i].ToString());
}
System.Runtime.InteropServices.Marshal.Copy(Bytes1, 0, p1.M_BitmapData.Scan0, num);
}
public void SetPixel(int x, int y, osf.Color color)
{
M_Bitmap.SetPixel(x, y, color.M_Color);
}
public string ToBase64String(ImageFormat format = null)
{
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
if (format != null)
{
M_Bitmap.Save((System.IO.Stream)memoryStream, format.M_ImageFormat);
}
else
{
try
{
M_Bitmap.Save((System.IO.Stream)memoryStream, M_Bitmap.RawFormat);
}
catch
{
M_Bitmap.Save((System.IO.Stream)memoryStream, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
string base64String = Convert.ToBase64String(memoryStream.ToArray());
memoryStream.Close();
return base64String;
}
public void UnlockBits(osf.BitmapData p1)
{
M_Bitmap.UnlockBits(p1.M_BitmapData);
}
}
[ContextClass("КлКартинка", "ClBitmap")]
public class ClBitmap : AutoContext<ClBitmap>
{
public ClBitmap(ClSize p1)
{
Bitmap Bitmap1 = new Bitmap(p1.Base_obj);
Bitmap1.dll_obj = this;
Base_obj = Bitmap1;
}
public ClBitmap(Image p1)
{
Bitmap Bitmap1 = new Bitmap(p1);
Bitmap1.dll_obj = this;
Base_obj = Bitmap1;
}
public ClBitmap(Image p1, ClSize p2)
{
Bitmap Bitmap1 = new Bitmap(p1, p2.Base_obj);
Bitmap1.dll_obj = this;
Base_obj = Bitmap1;
}
public ClBitmap(string p1)
{
Bitmap Bitmap1 = new Bitmap(p1);
Bitmap1.dll_obj = this;
Base_obj = Bitmap1;
}
public ClBitmap(ClStream p1)
{
Bitmap Bitmap1 = new Bitmap(p1.Base_obj);
Bitmap1.dll_obj = this;
Base_obj = Bitmap1;
}
public ClBitmap(ClBitmap p1)
{
Bitmap Bitmap1 = p1.Base_obj;
Bitmap1.dll_obj = this;
Base_obj = Bitmap1;
}
public Bitmap Base_obj;
[ContextProperty("Высота", "Height")]
public int Height
{
get { return Base_obj.Height; }
}
private string name;
[ContextProperty("Имя", "Name")]
public string Name
{
get { return name; }
set { name = value; }
}
[ContextProperty("Размер", "Size")]
public ClSize Size
{
get { return (ClSize)OneScriptForms.RevertObj(Base_obj.Size); }
}
[ContextProperty("ФорматПикселей", "PixelFormat")]
public int PixelFormat
{
get { return (int)Base_obj.PixelFormat; }
}
[ContextProperty("ФорматФайлаИзображения", "RawFormat")]
public ClImageFormat RawFormat
{
get { return (ClImageFormat)OneScriptForms.RevertObj(Base_obj.RawFormat); }
}
[ContextProperty("Ширина", "Width")]
public int Width
{
get { return Base_obj.Width; }
}
[ContextMethod("Блокировать", "LockBits")]
public ClBitmapData LockBits()
{
return new ClBitmapData(Base_obj.LockBits());
}
[ContextMethod("ЗакодироватьВСтроку", "ToBase64String")]
public string ToBase64String(ClImageFormat p1 = null)
{
if (p1 == null)
{
return Base_obj.ToBase64String();
}
return Base_obj.ToBase64String(p1.Base_obj);
}
[ContextMethod("Клонировать", "Clone")]
public ClBitmap Clone(int p1, int p2, int p3, int p4)
{
Bitmap Bitmap1 = Base_obj.Clone(Convert.ToSingle(p1), Convert.ToSingle(p2), Convert.ToSingle(p3), Convert.ToSingle(p4));
return new ClBitmap(Bitmap1);
}
[ContextMethod("Освободить", "Dispose")]
public void Dispose()
{
Base_obj.Dispose();
}
[ContextMethod("ПолучитьБайты", "GetBytes")]
public ClArrayList GetBytes(ClBitmapData p1)
{
return new ClArrayList(Base_obj.GetBytes(p1.Base_obj));
}
[ContextMethod("ПолучитьПиксель", "GetPixel")]
public ClColor GetPixel(int p1, int p2)
{
return new ClColor(Base_obj.GetPixel(p1, p2));
}
[ContextMethod("Разблокировать", "UnlockBits")]
public void UnlockBits(ClBitmapData p1)
{
Base_obj.UnlockBits(p1.Base_obj);
}
[ContextMethod("СделатьПрозрачным", "MakeTransparent")]
public void MakeTransparent(ClColor p1)
{
Base_obj.MakeTransparent(p1.Base_obj);
}
[ContextMethod("Сохранить", "Save")]
public void Save(IValue p1, ClImageFormat p2 = null)
{
if (p1.GetType() == typeof(osf.ClStream))
{
Base_obj.Save(((ClStream)p1).Base_obj, p2.Base_obj);
}
else
{
Base_obj.Save(p1.AsString(), p2.Base_obj);
}
}
[ContextMethod("УстановитьБайты", "SetBytes")]
public void SetBytes(ClBitmapData p1, ClArrayList p2)
{
Base_obj.SetBytes(p1.Base_obj, p2.Base_obj);
}
[ContextMethod("УстановитьПиксель", "SetPixel")]
public void SetPixel(int p1, int p2, ClColor p3)
{
Base_obj.SetPixel(p1, p2, p3.Base_obj);
}
}
}