Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2484 | - | 1 | using System.Drawing; |
2 | using System.Runtime.Serialization; |
||
3 | |||
4 | namespace Touchless.Vision.Contracts |
||
5 | { |
||
6 | [DataContract] |
||
7 | public class DetectedObject |
||
8 | { |
||
9 | private static readonly object SyncObject = new object(); |
||
10 | private static int _nextId = 1; |
||
11 | |||
12 | public DetectedObject() |
||
13 | { |
||
14 | Id = NextId(); |
||
15 | } |
||
16 | |||
17 | [DataMember] |
||
18 | public int Id { get; private set; } |
||
19 | |||
20 | [IgnoreDataMember] |
||
21 | public Bitmap Image { get; set; } |
||
22 | |||
23 | //[DataMember] |
||
24 | //public byte[] ImageData |
||
25 | //{ |
||
26 | // get |
||
27 | // { |
||
28 | // byte[] data = null; |
||
29 | // if (this.Image != null) |
||
30 | // { |
||
31 | // MemoryStream memoryStream = new MemoryStream(); |
||
32 | // this.Image.Save(memoryStream, ImageFormat.Bmp); |
||
33 | // memoryStream.Flush(); |
||
34 | // data = memoryStream.ToArray(); |
||
35 | // memoryStream.Close(); |
||
36 | // } |
||
37 | |||
38 | // return data; |
||
39 | |||
40 | |||
41 | // } |
||
42 | //} |
||
43 | |||
44 | [DataMember] |
||
45 | public virtual Point Position { get; set; } |
||
46 | |||
47 | public void AssignNewId() |
||
48 | { |
||
49 | Id = NextId(); |
||
50 | } |
||
51 | |||
52 | |||
53 | private static int NextId() |
||
54 | { |
||
55 | int result; |
||
56 | lock (SyncObject) |
||
57 | { |
||
58 | result = _nextId; |
||
59 | _nextId++; |
||
60 | } |
||
61 | |||
62 | return result; |
||
63 | } |
||
64 | } |
||
65 | } |