/[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 86 - (show 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 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using gr2lib.core.helpers;
5 using gr2lib.core.interfaces;
6 namespace gr2lib.core.coretypes.implementation
7 {
8 public class Image : IImage
9 {
10
11
12
13 public Image()
14 {
15 this.MIPLevels = new List<MIPLevel>();
16 //this.NativePointer = IntPtr.Zero;
17 }
18
19 internal static Image ReadFromMemory(IntPtr pointer)
20 {
21 try
22 {
23 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 }
29 catch (Exception ex)
30 {
31 Console.WriteLine(ex.ToString());
32 return default(Image);
33 }
34 }
35
36 internal static Image ReadFromNative(native.Image native)
37 {
38 try
39 {
40 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 }
56 catch (Exception ex)
57 {
58 Console.WriteLine(ex.ToString());
59 return default(Image);
60 }
61 }
62
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 }
73 }

  ViewVC Help
Powered by ViewVC 1.1.22