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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95 - (show annotations) (download)
Sat Jul 17 05:10:22 2010 UTC (9 years, 7 months ago) by william
File size: 2579 byte(s)
add StackTrace support for error handling (to see the stack calls)

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using gr2lib.core.helpers;
5 using gr2lib.core.interfaces;
6 using System.Diagnostics;
7 namespace gr2lib.core.coretypes.implementation
8 {
9 public class Image : IImage
10 {
11
12
13
14 public Image()
15 {
16 this.MIPLevels = new List<MIPLevel>();
17 //this.NativePointer = IntPtr.Zero;
18 }
19
20 internal static Image ReadFromMemory(IntPtr pointer)
21 {
22 try
23 {
24 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 }
30 catch (Exception ex)
31 {
32 StackTrace st = new StackTrace(true);
33 Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
34 return default(Image);
35 }
36 }
37
38 internal static Image ReadFromNative(native.Image native)
39 {
40 try
41 {
42 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 }
58 catch (Exception ex)
59 {
60 StackTrace st = new StackTrace(true);
61 Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
62 return default(Image);
63 }
64 }
65
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 }
76 }

  ViewVC Help
Powered by ViewVC 1.1.22