If you want to load .jpg file with GdiPlusRasterLayer, there are two ways, one is you have corresponding world file .jgw file, your code works for it; the other way is you don’t have .jpw file, you need to pass in the RectangleShape represent world extent in constructor of GdiPlusRasterLayer, for example, rasterLayer = New GdiPlusRasterLayer(filename, new RectangleShape(-180,90,180,-90))
As per your guideline, Now I am able to open the .jpg file. Since I have not .jgw file, so here I put RectangleSpape(-180,90,180,-90), the image open but with lot zoom. First time map loaded with zoom but no error. Now we remove (or close) layer from Map Control and again open the same file, its give error out of memory. My .JPG file size is 17.8 MB. So, here my concern is :
1. I have to open different .jpg file, so we can not fix the RectangleShape(-180,90,180,-90). Is there any other method which will give the current extent of .jpg file?
2. How we control exception "Out of Memory"?
3. Is projection required for .JPG file? if yes, how we can set the projection of .JPG file.
The extent of the map is not always that value, it’s just an example, If you know your .jpg file represents which extent, you can set the corresponding value, for example, your image represent India boundary, you can set the India extent. Raster layer is not like feature layer which can get extent by itself, you can ask the image provider to give you the extent or corresponding world file.
I think the out of memory problem may cause by the incorrect code, such as, you didn’t close your raster layer before remove it from map control.
For 1st Point: It means if I have not corresponding world file, the I have to use always India boundry, If we are using different .JPG file of city? Because we can fix only a single extent or it is not possible to put different extent by user at the time of map loading.
For 2nd Point: When I am loading image file, I am using following code Directcast(WinformsMap1.Overlays(0),LayerOverlay).Layers.Add(layername,rasterlayer), here layername is name of layer.
At the time of closing layer I am using following code: DirectCast(WinformsMap1.Overlays(0),LayerOverlay).Layers.Clear()
Even I tried rasterlayer.Close, after loading of Image but the same message "Out of Memory" coming.
If the user know the bounding box of his .jpg file, he can generate corresponding world file manually, and then running the application, so that the map loading can load the different .jpg file with .jpw file.
Close layer after loading map may not have effect, because we will call Open() again during render map, you need to close layer before remove it from layers. the code is like below: DirectCast(WinformsMap1.Overlays(0),LayerOverlay).Layers("layername").Close() DirectCast(WinformsMap1.Overlays(0),LayerOverlay).Layers.Clear() If you still have problem, could you provide a simple sample that can recreate it, and can you upload your .jpg file to our Ftp that I can test.
I have Implemented code as per your guidence and its working OK but some .JPG file has issue and that not open at very first moment. Lets give example. Suppose I have 3 .JPG file. The two file are working and one file not open and its throw same message "Out of memory" in first attempt. The file size 11.5 MB.
Second thing can you guide me, how to generate corresponding world file manually?