Hello,
I’m trying to make some manipulation on “.tif” image
you can download the file from here:
Once the following code is invoked, I receive System.IndexOutOfRangeException, the exception is thrown on the layer.ImageSource.GetImage line.
public void Init(RasterLayer layer)
{
RectangleShape ImageBounds = layer.GetBoundingBox();
int ImageHeight = layer.ImageSource.GetImageHeight();
int ImageWidth = layer.ImageSource.GetImageWidth();
using (GeoImage sourceGeoImage = layer.ImageSource.GetImage(ImageBounds, ImageWidth, ImageHeight))
{
…
…
…
}
}
Values received from the “layer” and “layer.ImageSource” are:
ImageBounds = {-180.00000406988,89.9999964404851,180.000014705583,-90.0000129472464}
base: {-180.00000406988,89.9999964404851,180.000014705583,-90.0000129472464}
Height: 180.00000938773155
LowerLeftPoint: {-180.00000406988,-90.0000129472464,0}
LowerRightPoint: {180.000014705583,-90.0000129472464,0}
UpperLeftPoint: {-180.00000406988,89.9999964404851,0}
UpperRightPoint: {180.000014705583,89.9999964404851,0}
Width: 360.0000187754631
ImageHeight = 5400
ImageWidth = 10800
Could you please shed some light on the behavior of the GetImage method, The API of that function describes only ArgumentOutOfRangeException, which is thrown in case of height or width being lower or equal to 0 but neither is true in this case, but the IndexOutOfRagneException never mentioned in the API.
To overcome this problem I’ve tried to modify the values of both the ImageBounds and ImageHeight and ImageWidth. In case of ImageBounds modifications, I’ve changed the value to:
ImageBounds = {-179,89.9999964404851,179,-89.9999964404851}
base: {-179,89.9999964404851,179,-89.9999964404851}
Height: 179.99999288097021
LowerLeftPoint: {-179,-89.9999964404851,0}
LowerRightPoint: {179,-89.9999964404851,0}
UpperLeftPoint: {-179,89.9999964404851,0}
UpperRightPoint: {179,89.9999964404851,0}
Width: 358.0
And no exception happened
In case of ImageHeight and ImageWidth I’ve tried to change the values to
ImageHeight = 5000
ImageWidth = 10000
and again no crash happened.
Those are just experimental arbitrary values, and the injection of these values were done seperatly, in other words, one execution with modifying only ImageBounds, and another separate execution with modifying only ImageHeight and ImageWidth (both ImageHeight and ImageWidth in single execution).
Now I’m not sure about the correlation between the world extent argument to the height and width of the GetImage method so I definitely can’t implement some normalization logic for the images, because the images might be whatever the user might load in the application. But this Image does create and reproduce this exception each time, therefore same situation might happen for other images as well and surely the application must be able to deal with such a matter.
can you please advice?