/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/Image.cs
ViewVC logotype

Annotation of /trunk/gr2lib/core/coretypes/implementation/Image.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 86 - (hide annotations) (download)
Fri Jul 16 23:35:21 2010 UTC (9 years, 6 months ago) by william
File size: 2352 byte(s)
Add Try/Catch blocks in to all API Calls

1 william 72 using System;
2     using System.Collections.Generic;
3     using System.Text;
4     using gr2lib.core.helpers;
5 william 79 using gr2lib.core.interfaces;
6 william 72 namespace gr2lib.core.coretypes.implementation
7     {
8 william 79 public class Image : IImage
9 william 72 {
10 william 79
11 william 72
12    
13 william 73 public Image()
14     {
15     this.MIPLevels = new List<MIPLevel>();
16 william 83 //this.NativePointer = IntPtr.Zero;
17 william 73 }
18    
19 william 72 internal static Image ReadFromMemory(IntPtr pointer)
20     {
21 william 86 try
22     {
23 william 72 if (pointer == IntPtr.Zero) return null;
24     native.Image native = Helpers.ReadFromMemory<native.Image>(pointer);
25     Image managed = ReadFromNative(native);
26     managed.NativePointer = pointer;
27     return managed;
28 william 86 }
29     catch (Exception ex)
30     {
31     Console.WriteLine(ex.ToString());
32     return default(Image);
33     }
34 william 72 }
35    
36     internal static Image ReadFromNative(native.Image native)
37     {
38 william 86 try
39 william 72 {
40 william 86 Image managed = new Image();
41     IntPtr[] miplevels = Helpers.ReadPtrArrayFromMemory<native.MIPLevel>(native.MIPLevels);
42     int length = miplevels.Length;
43     managed.MIPLevels = new List<MIPLevel>(length);
44     foreach (IntPtr ptr in miplevels)
45     {
46     MIPLevel _tmp = new MIPLevel();
47     _tmp.NativePointer = ptr;
48     managed.MIPLevels.Add(_tmp);
49     }
50     for (int i = 0; i < length; i++)
51     {
52     managed.MIPLevels[i] = MIPLevel.ReadFromMemory(miplevels[i]);
53     }
54     return managed;
55 william 72 }
56 william 86 catch (Exception ex)
57 william 72 {
58 william 86 Console.WriteLine(ex.ToString());
59     return default(Image);
60 william 72 }
61     }
62 william 79
63     #region INativePointer Members
64     private IntPtr _NativePointer;
65     public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
66     #endregion
67    
68     #region IImage Members
69     private List<MIPLevel> _MIPLevels;
70     public List<MIPLevel> MIPLevels { get { return _MIPLevels; } set { _MIPLevels = value; } }
71     #endregion
72 william 72 }
73     }

  ViewVC Help
Powered by ViewVC 1.1.22