@@ -80,19 +80,37 @@ private static Image<Rgb24> CreateImageFromRgbaData(byte[] rgbaData, int width,
8080 }
8181 public byte [ ] GetTile ( TileInfo tileInfo , ZCT coord )
8282 {
83- var r = Schema . Resolutions [ tileInfo . Index . Level ] . UnitsPerPixel ;
84- var tileWidth = Schema . Resolutions [ tileInfo . Index . Level ] . TileWidth ;
85- var tileHeight = Schema . Resolutions [ tileInfo . Index . Level ] . TileHeight ;
86- var curLevelOffsetXPixel = tileInfo . Extent . MinX / MinUnitsPerPixel ;
87- var curLevelOffsetYPixel = - tileInfo . Extent . MaxY / MinUnitsPerPixel ;
88- var curTileWidth = ( int ) ( tileInfo . Extent . MaxX > Schema . Extent . Width ? tileWidth - ( tileInfo . Extent . MaxX - Schema . Extent . Width ) / r : tileWidth ) ;
89- var curTileHeight = ( int ) ( - tileInfo . Extent . MinY > Schema . Extent . Height ? tileHeight - ( - tileInfo . Extent . MinY - Schema . Extent . Height ) / r : tileHeight ) ;
90- var bgraData = SlideImage . ReadRegion ( tileInfo . Index . Level , coord , ( long ) curLevelOffsetXPixel , ( long ) curLevelOffsetYPixel , curTileWidth , curTileHeight ) ;
91- //We check to see if the data is valid.
92- if ( bgraData . Length != curTileWidth * curTileHeight * 4 )
93- return null ;
94- byte [ ] bm = ConvertRgbaToRgb ( bgraData ) ;
95- return bm ;
83+ try
84+ {
85+ if ( Schema == null )
86+ {
87+ Console . WriteLine ( "Schema is null." ) ;
88+ return null ;
89+ }
90+ var r = Schema . Resolutions [ tileInfo . Index . Level ] . UnitsPerPixel ;
91+ var tileWidth = Schema . Resolutions [ tileInfo . Index . Level ] . TileWidth ;
92+ var tileHeight = Schema . Resolutions [ tileInfo . Index . Level ] . TileHeight ;
93+ var curLevelOffsetXPixel = tileInfo . Extent . MinX / MinUnitsPerPixel ;
94+ var curLevelOffsetYPixel = - tileInfo . Extent . MaxY / MinUnitsPerPixel ;
95+ var curTileWidth = ( int ) ( tileInfo . Extent . MaxX > Schema . Extent . Width ? tileWidth - ( tileInfo . Extent . MaxX - Schema . Extent . Width ) / r : tileWidth ) ;
96+ var curTileHeight = ( int ) ( - tileInfo . Extent . MinY > Schema . Extent . Height ? tileHeight - ( - tileInfo . Extent . MinY - Schema . Extent . Height ) / r : tileHeight ) ;
97+ if ( SlideImage == null )
98+ {
99+ Console . WriteLine ( "SlideImage is null." ) ;
100+ return null ;
101+ }
102+ var bgraData = SlideImage . ReadRegion ( tileInfo . Index . Level , coord , ( long ) curLevelOffsetXPixel , ( long ) curLevelOffsetYPixel , curTileWidth , curTileHeight ) ;
103+ //We check to see if the data is valid.
104+ if ( bgraData . Length != curTileWidth * curTileHeight * 4 )
105+ return null ;
106+ byte [ ] bm = ConvertRgbaToRgb ( bgraData ) ;
107+ return bm ;
108+ }
109+ catch ( Exception e )
110+ {
111+ Console . WriteLine ( e . Message + " " + e . StackTrace ) ;
112+ }
113+ return null ;
96114 }
97115 public static byte [ ] ConvertRgbaToRgb ( byte [ ] rgbaArray )
98116 {
0 commit comments