/[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 95 - (hide annotations) (download)
Sat Jul 17 05:10:22 2010 UTC (9 years, 6 months ago) by william
File size: 2579 byte(s)
add StackTrace support for error handling (to see the stack 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 95 using System.Diagnostics;
7 william 72 namespace gr2lib.core.coretypes.implementation
8     {
9 william 79 public class Image : IImage
10 william 72 {
11 william 79
12 william 72
13    
14 william 73 public Image()
15     {
16     this.MIPLevels = new List<MIPLevel>();
17 william 83 //this.NativePointer = IntPtr.Zero;
18 william 73 }
19    
20 william 72 internal static Image ReadFromMemory(IntPtr pointer)
21     {
22 william 86 try
23     {
24 william 72 if (pointer == IntPtr.Zero) return null;
25     native.Image native = Helpers.ReadFromMemory<native.Image>(pointer);
26     Image managed = ReadFromNative(native);
27     managed.NativePointer = pointer;
28     return managed;
29 william 86 }
30     catch (Exception ex)
31     {
32 william 95 StackTrace st = new StackTrace(true);
33     Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
34 william 86 return default(Image);
35     }
36 william 72 }
37    
38     internal static Image ReadFromNative(native.Image native)
39     {
40 william 86 try
41 william 72 {
42 william 86 Image managed = new Image();
43     IntPtr[] miplevels = Helpers.ReadPtrArrayFromMemory<native.MIPLevel>(native.MIPLevels);
44     int length = miplevels.Length;
45     managed.MIPLevels = new List<MIPLevel>(length);
46     foreach (IntPtr ptr in miplevels)
47     {
48     MIPLevel _tmp = new MIPLevel();
49     _tmp.NativePointer = ptr;
50     managed.MIPLevels.Add(_tmp);
51     }
52     for (int i = 0; i < length; i++)
53     {
54     managed.MIPLevels[i] = MIPLevel.ReadFromMemory(miplevels[i]);
55     }
56     return managed;
57 william 72 }
58 william 86 catch (Exception ex)
59 william 72 {
60 william 95 StackTrace st = new StackTrace(true);
61     Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
62 william 86 return default(Image);
63 william 72 }
64     }
65 william 79
66     #region INativePointer Members
67     private IntPtr _NativePointer;
68     public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
69     #endregion
70    
71     #region IImage Members
72     private List<MIPLevel> _MIPLevels;
73     public List<MIPLevel> MIPLevels { get { return _MIPLevels; } set { _MIPLevels = value; } }
74     #endregion
75 william 72 }
76     }

  ViewVC Help
Powered by ViewVC 1.1.22