Out of memory, Argument Exception (picturebox control )in .net CF

G

Guest

Hi,
I need help to handle out of memory, argument exception my .net CF 1.1
pocket pc application is throwing. Basically the following code will accept
gps latitude and longitude coordinates as arguments and display image
returned from a mappoint webservice in a picturebox control and this code is
called repeatively until there were no Gps LAt/long coordinates.

And here is my code

private void GetMapImage(double latit,double longit)
{
try
{
double latit1,longit1;
latit1=latit;
longit1=longit;
Credentials();
LatLong myLatLong=new LatLong();
myLatLong.Latitude=latit;
myLatLong.Longitude=longit;
Location[] returnedLocations;
returnedLocations = findService.GetLocationInfo(myLatLong, "MapPoint.NA",
null);
FindAddressSpecification myaddress= new FindAddressSpecification();
myaddress.DataSourceName="Mappoint.NA";
myaddress.InputAddress=returnedLocations[0].Address;
FindResults results =new FindResults();
results = findService.FindAddress(myaddress);
myViews[0] = results.Results0].FoundLocation.BestMapView.ByHeightWidth;

//Displaying Pushpins
Pushpin[] myPushpins = new Pushpin[1];
myPushpins[0] = new Pushpin();
myPushpins[0].IconDataSource="MapPoint.Icons";
myPushpins[0].IconName = "32";
myPushpins[0].Label = WrapText("You are here",10);
myPushpins[0].LatLong =myViews[0].CenterPoint;
myPushpins[0].ReturnsHotArea=true;
MapSpecification mapSpec = new MapSpecification();
Point MapDimensions=new Point();
mapSpec.DataSourceName ="MapPoint.NA";
mapSpec.Options=new MapOptions();
mapSpec.Options.ReturnType=MapReturnType.ReturnImage;
mapSpec.Options.Format=new ImageFormat();

mapSpec.Options.Format.MimeType="image/png";

mapSpec.Options.Format.Width=pbMyLocationMap.Width;
mapSpec.Options.Format.Height=pbMyLocationMap.Height;
mapSpec.Views = myViews;
mapSpec.Pushpins = myPushpins;

//Displaying the Map
MapImage[] mapImages =RenderService.GetMap(mapSpec);
pbMyLocationMap.Image= new Bitmap(new
System.IO.MemoryStreammapImages[0].MimeData.Bits));

}
catch(System.OutOfMemoryException ex)
{
throw new Exception(ex.Message,ex);
}
catch(System.ArgumentException ex)
{
throw new Exception(ex.Message,ex);
}

}----> Argument exception is showing at the following location. I didnt get
whats going on. Don' know how to print the stack trace information in .net
CF1.1 .net 2003 c#

And someone suggested not to load the bitmap in C# smart device applications.

Anyone pls guide me.

Thanks so much in advance,
 
H

Hilton

See recent thread on Dispose(). The way MS have implemented Bitmap, you
have to do your own memory management... just when you thought it was safe
to...

Anyway, keep a reference to the Bitmap, for example:

if (this.bmp != null)
{
this.bmp.Dispose ();
}
this.bmp = new Bitmap(new
System.IO.MemoryStreammapImages[0].MimeData.Bits));

Also remember to Dispose() when you're done with the last Bitmap. Modify
this code as you see fit, but just make sure that you have a Dispose() for
every "new Bitmap"; if this sounds like malloc/free, well, that's exactly
what it is.

Hilton



abcdef said:
Hi,
I need help to handle out of memory, argument exception my .net CF 1.1
pocket pc application is throwing. Basically the following code will
accept
gps latitude and longitude coordinates as arguments and display image
returned from a mappoint webservice in a picturebox control and this code
is
called repeatively until there were no Gps LAt/long coordinates.

And here is my code

private void GetMapImage(double latit,double longit)
{
try
{
double latit1,longit1;
latit1=latit;
longit1=longit;
Credentials();
LatLong myLatLong=new LatLong();
myLatLong.Latitude=latit;
myLatLong.Longitude=longit;
Location[] returnedLocations;
returnedLocations = findService.GetLocationInfo(myLatLong, "MapPoint.NA",
null);
FindAddressSpecification myaddress= new FindAddressSpecification();
myaddress.DataSourceName="Mappoint.NA";
myaddress.InputAddress=returnedLocations[0].Address;
FindResults results =new FindResults();
results = findService.FindAddress(myaddress);
myViews[0] = results.Results0].FoundLocation.BestMapView.ByHeightWidth;

//Displaying Pushpins
Pushpin[] myPushpins = new Pushpin[1];
myPushpins[0] = new Pushpin();
myPushpins[0].IconDataSource="MapPoint.Icons";
myPushpins[0].IconName = "32";
myPushpins[0].Label = WrapText("You are here",10);
myPushpins[0].LatLong =myViews[0].CenterPoint;
myPushpins[0].ReturnsHotArea=true;
MapSpecification mapSpec = new MapSpecification();
Point MapDimensions=new Point();
mapSpec.DataSourceName ="MapPoint.NA";
mapSpec.Options=new MapOptions();
mapSpec.Options.ReturnType=MapReturnType.ReturnImage;
mapSpec.Options.Format=new ImageFormat();

mapSpec.Options.Format.MimeType="image/png";

mapSpec.Options.Format.Width=pbMyLocationMap.Width;
mapSpec.Options.Format.Height=pbMyLocationMap.Height;
mapSpec.Views = myViews;
mapSpec.Pushpins = myPushpins;

//Displaying the Map
MapImage[] mapImages =RenderService.GetMap(mapSpec);
pbMyLocationMap.Image= new Bitmap(new
System.IO.MemoryStreammapImages[0].MimeData.Bits));

}
catch(System.OutOfMemoryException ex)
{
throw new Exception(ex.Message,ex);
}
catch(System.ArgumentException ex)
{
throw new Exception(ex.Message,ex);
}

}----> Argument exception is showing at the following location. I didnt
get
whats going on. Don' know how to print the stack trace information in .net
CF1.1 .net 2003 c#

And someone suggested not to load the bitmap in C# smart device
applications.

Anyone pls guide me.

Thanks so much in advance,
 
H

Hilton

Oh, another thing that might help, is to read the stream into a byte[], and
use that to do your new Bitmap.

Hilton
 
G

Guest

Hi hilton,
Thanks for your reply. I implemented your suggestions and still getting
Argument Exception at the location I pointed out in my previous post.

Any ideas regarding this is so helpful.

thanks in advance,


Hilton said:
Oh, another thing that might help, is to read the stream into a byte[], and
use that to do your new Bitmap.

Hilton


abcdef said:
Hi,
I need help to handle out of memory, argument exception my .net CF 1.1
pocket pc application is throwing. Basically the following code will
accept
gps latitude and longitude coordinates as arguments and display image
returned from a mappoint webservice in a picturebox control and this code
is
called repeatively until there were no Gps LAt/long coordinates.

And here is my code

private void GetMapImage(double latit,double longit)
{
try
{
double latit1,longit1;
latit1=latit;
longit1=longit;
Credentials();
LatLong myLatLong=new LatLong();
myLatLong.Latitude=latit;
myLatLong.Longitude=longit;
Location[] returnedLocations;
returnedLocations = findService.GetLocationInfo(myLatLong, "MapPoint.NA",
null);
FindAddressSpecification myaddress= new FindAddressSpecification();
myaddress.DataSourceName="Mappoint.NA";
myaddress.InputAddress=returnedLocations[0].Address;
FindResults results =new FindResults();
results = findService.FindAddress(myaddress);
myViews[0] = results.Results0].FoundLocation.BestMapView.ByHeightWidth;

//Displaying Pushpins
Pushpin[] myPushpins = new Pushpin[1];
myPushpins[0] = new Pushpin();
myPushpins[0].IconDataSource="MapPoint.Icons";
myPushpins[0].IconName = "32";
myPushpins[0].Label = WrapText("You are here",10);
myPushpins[0].LatLong =myViews[0].CenterPoint;
myPushpins[0].ReturnsHotArea=true;
MapSpecification mapSpec = new MapSpecification();
Point MapDimensions=new Point();
mapSpec.DataSourceName ="MapPoint.NA";
mapSpec.Options=new MapOptions();
mapSpec.Options.ReturnType=MapReturnType.ReturnImage;
mapSpec.Options.Format=new ImageFormat();

mapSpec.Options.Format.MimeType="image/png";

mapSpec.Options.Format.Width=pbMyLocationMap.Width;
mapSpec.Options.Format.Height=pbMyLocationMap.Height;
mapSpec.Views = myViews;
mapSpec.Pushpins = myPushpins;

//Displaying the Map
MapImage[] mapImages =RenderService.GetMap(mapSpec);
pbMyLocationMap.Image= new Bitmap(new
System.IO.MemoryStreammapImages[0].MimeData.Bits));

}
catch(System.OutOfMemoryException ex)
{
throw new Exception(ex.Message,ex);
}
catch(System.ArgumentException ex)
{
throw new Exception(ex.Message,ex);
}

}----> Argument exception is showing at the following location. I didnt
get
whats going on. Don' know how to print the stack trace information in .net
CF1.1 .net 2003 c#

And someone suggested not to load the bitmap in C# smart device
applications.

Anyone pls guide me.

Thanks so much in advance,
 
H

Hilton

OK WARNING, extremely hacky debug code:

int error = 0;

put an "error = 1", "error = 2" etc on alternating lines, then print error
when an exception gets thrown. Alternatively you can use VS to debug the
app, but sometimes good ol' fashion debugging works. This will tell you
what line the ArgumentException gets thrown.

What is an "Out of Memory, Argument Exception"? It is one or the other,
which one are you getting? Also, tell us exactly which line is throwing it
(see above).

Hilton


abcdef said:
Hi hilton,
Thanks for your reply. I implemented your suggestions and still getting
Argument Exception at the location I pointed out in my previous post.

Any ideas regarding this is so helpful.

thanks in advance,


Hilton said:
Oh, another thing that might help, is to read the stream into a byte[],
and
use that to do your new Bitmap.

Hilton


abcdef said:
Hi,
I need help to handle out of memory, argument exception my .net CF 1.1
pocket pc application is throwing. Basically the following code will
accept
gps latitude and longitude coordinates as arguments and display image
returned from a mappoint webservice in a picturebox control and this
code
is
called repeatively until there were no Gps LAt/long coordinates.

And here is my code

private void GetMapImage(double latit,double longit)
{
try
{
double latit1,longit1;
latit1=latit;
longit1=longit;
Credentials();
LatLong myLatLong=new LatLong();
myLatLong.Latitude=latit;
myLatLong.Longitude=longit;
Location[] returnedLocations;
returnedLocations = findService.GetLocationInfo(myLatLong,
"MapPoint.NA",
null);
FindAddressSpecification myaddress= new FindAddressSpecification();
myaddress.DataSourceName="Mappoint.NA";
myaddress.InputAddress=returnedLocations[0].Address;
FindResults results =new FindResults();
results = findService.FindAddress(myaddress);
myViews[0] = results.Results0].FoundLocation.BestMapView.ByHeightWidth;

//Displaying Pushpins
Pushpin[] myPushpins = new Pushpin[1];
myPushpins[0] = new Pushpin();
myPushpins[0].IconDataSource="MapPoint.Icons";
myPushpins[0].IconName = "32";
myPushpins[0].Label = WrapText("You are here",10);
myPushpins[0].LatLong =myViews[0].CenterPoint;
myPushpins[0].ReturnsHotArea=true;
MapSpecification mapSpec = new MapSpecification();
Point MapDimensions=new Point();
mapSpec.DataSourceName ="MapPoint.NA";
mapSpec.Options=new MapOptions();
mapSpec.Options.ReturnType=MapReturnType.ReturnImage;
mapSpec.Options.Format=new ImageFormat();

mapSpec.Options.Format.MimeType="image/png";

mapSpec.Options.Format.Width=pbMyLocationMap.Width;
mapSpec.Options.Format.Height=pbMyLocationMap.Height;
mapSpec.Views = myViews;
mapSpec.Pushpins = myPushpins;

//Displaying the Map
MapImage[] mapImages =RenderService.GetMap(mapSpec);
pbMyLocationMap.Image= new Bitmap(new
System.IO.MemoryStreammapImages[0].MimeData.Bits));

}
catch(System.OutOfMemoryException ex)
{
throw new Exception(ex.Message,ex);
}
catch(System.ArgumentException ex)
{
throw new Exception(ex.Message,ex);
}

}----> Argument exception is showing at the following location. I didnt
get
whats going on. Don' know how to print the stack trace information in
.net
CF1.1 .net 2003 c#

And someone suggested not to load the bitmap in C# smart device
applications.

Anyone pls guide me.

Thanks so much in advance,
 
G

Guest

Hi hilton,

After I implemented dispose method in my picturebox.image , my application
stopped throwing Out of Memory Exception.

I am now working towards the other exception ->Argument Exception that my
application is throwing..

And I debug the code as suggested, still didnt find useful information to
handle the exception.

Here is mycode again

rivate void GetMapImage(double latit,double longit)
{
int error=0;
try
{
double latit1,longit1;
latit1=latit;
longit1=longit;
Credentials();
LatLong myLatLong=new LatLong();
myLatLong.Latitude=latit;
myLatLong.Longitude=longit;
Location[] returnedLocations;
returnedLocations = findService.GetLocationInfo(myLatLong,
"MapPoint.NA", null);
FindAddressSpecification myaddress= new FindAddressSpecification();
myaddress.DataSourceName="Mappoint.NA";
myaddress.InputAddress=returnedLocations[0].Address;
FindResults results =new FindResults();
results = findService.FindAddress(myaddress);
myViews[0] = results.Results[0].FoundLocation.BestMapView.ByHeightWidth;

//Displaying Pushpins
Pushpin[] myPushpins = new Pushpin[1];
myPushpins[0] = new Pushpin();
myPushpins[0].IconDataSource="MapPoint.Icons";
myPushpins[0].IconName = "32";
myPushpins[0].Label = WrapText("You are here",10);
myPushpins[0].LatLong =myViews[0].CenterPoint;
myPushpins[0].ReturnsHotArea=true;

MapSpecification mapSpec = new MapSpecification();
Point MapDimensions=new Point();
mapSpec.DataSourceName ="MapPoint.NA";
mapSpec.Options=new MapOptions();
mapSpec.Options.ReturnType=MapReturnType.ReturnImage;
mapSpec.Options.Format=new ImageFormat();
mapSpec.Options.Format.MimeType="image/png";
mapSpec.Options.Format.Width=pbMyLocationMap.Width;
mapSpec.Options.Format.Height=pbMyLocationMap.Height;

mapSpec.Views = myViews;
mapSpec.Pushpins = myPushpins;

//Displaying the Map
MapImage[] mapImages =RenderService.GetMap(mapSpec);
Byte[] byteData = new Byte[0];
byteData = (Byte[])(mapImages[0].MimeData.Bits);
MemoryStream ms = new MemoryStream(byteData);
pbMyLocationMap.Image=new Bitmap(ms);
error=1;
}
//pbMyLocationMap.Image= new Bitmap(new
System.IO.MemoryStream(mapImages[0].MimeData.Bits));
catch(System.ArgumentException ex)
{
throw new Exception(ex.Message,ex);
}
try
{
error=2;
}catch(System.ArgumentException e){
throw new Exception(e.Message ,e);}

error=3;
}rivate void GetMapImage(double latit,double longit)
{
int error=0;
try
{
double latit1,longit1;
latit1=latit;
longit1=longit;
Credentials();
LatLong myLatLong=new LatLong();
myLatLong.Latitude=latit;
myLatLong.Longitude=longit;
Location[] returnedLocations;
returnedLocations = findService.GetLocationInfo(myLatLong,
"MapPoint.NA", null);
FindAddressSpecification myaddress= new FindAddressSpecification();
myaddress.DataSourceName="Mappoint.NA";
myaddress.InputAddress=returnedLocations[0].Address;
FindResults results =new FindResults();
results = findService.FindAddress(myaddress);
myViews[0] = results.Results[0].FoundLocation.BestMapView.ByHeightWidth;

//Displaying Pushpins
Pushpin[] myPushpins = new Pushpin[1];
myPushpins[0] = new Pushpin();
myPushpins[0].IconDataSource="MapPoint.Icons";
myPushpins[0].IconName = "32";
myPushpins[0].Label = WrapText("You are here",10);
myPushpins[0].LatLong =myViews[0].CenterPoint;
myPushpins[0].ReturnsHotArea=true;

MapSpecification mapSpec = new MapSpecification();
Point MapDimensions=new Point();
mapSpec.DataSourceName ="MapPoint.NA";
mapSpec.Options=new MapOptions();
mapSpec.Options.ReturnType=MapReturnType.ReturnImage;
mapSpec.Options.Format=new ImageFormat();
mapSpec.Options.Format.MimeType="image/png";
mapSpec.Options.Format.Width=pbMyLocationMap.Width;
mapSpec.Options.Format.Height=pbMyLocationMap.Height;

mapSpec.Views = myViews;
mapSpec.Pushpins = myPushpins;

//Displaying the Map
MapImage[] mapImages =RenderService.GetMap(mapSpec);
Byte[] byteData = new Byte[0];
byteData = (Byte[])(mapImages[0].MimeData.Bits);
MemoryStream ms = new MemoryStream(byteData);
pbMyLocationMap.Image=new Bitmap(ms);
error=1;
}
//pbMyLocationMap.Image= new Bitmap(new
System.IO.MemoryStream(mapImages[0].MimeData.Bits));
catch(System.ArgumentException ex)
{
throw new Exception(ex.Message,ex);
}
try
{
error=2;
}catch(System.ArgumentException e){
throw new Exception(e.Message ,e);}

error=3;
}rivate void GetMapImage(double latit,double longit)
{
int error=0;
try
{
double latit1,longit1;
latit1=latit;
longit1=longit;
Credentials();
LatLong myLatLong=new LatLong();
myLatLong.Latitude=latit;
myLatLong.Longitude=longit;
Location[] returnedLocations;
returnedLocations = findService.GetLocationInfo(myLatLong,
"MapPoint.NA", null);
FindAddressSpecification myaddress= new FindAddressSpecification();
myaddress.DataSourceName="Mappoint.NA";
myaddress.InputAddress=returnedLocations[0].Address;
FindResults results =new FindResults();
results = findService.FindAddress(myaddress);
myViews[0] = results.Results[0].FoundLocation.BestMapView.ByHeightWidth;

//Displaying Pushpins
Pushpin[] myPushpins = new Pushpin[1];
myPushpins[0] = new Pushpin();
myPushpins[0].IconDataSource="MapPoint.Icons";
myPushpins[0].IconName = "32";
myPushpins[0].Label = WrapText("You are here",10);
myPushpins[0].LatLong =myViews[0].CenterPoint;
myPushpins[0].ReturnsHotArea=true;

MapSpecification mapSpec = new MapSpecification();
Point MapDimensions=new Point();
mapSpec.DataSourceName ="MapPoint.NA";
mapSpec.Options=new MapOptions();
mapSpec.Options.ReturnType=MapReturnType.ReturnImage;
mapSpec.Options.Format=new ImageFormat();
mapSpec.Options.Format.MimeType="image/png";
mapSpec.Options.Format.Width=pbMyLocationMap.Width;
mapSpec.Options.Format.Height=pbMyLocationMap.Height;

mapSpec.Views = myViews;
mapSpec.Pushpins = myPushpins;

//Displaying the Map
MapImage[] mapImages =RenderService.GetMap(mapSpec);
Byte[] byteData = new Byte[0];
byteData = (Byte[])(mapImages[0].MimeData.Bits);
MemoryStream ms = new MemoryStream(byteData);
pbMyLocationMap.Image=new Bitmap(ms);
error=1;
}
//pbMyLocationMap.Image= new Bitmap(new
System.IO.MemoryStream(mapImages[0].MimeData.Bits));
catch(System.ArgumentException ex)
{
throw new Exception(ex.Message,ex);
}
try
{
error=2;
}catch(System.ArgumentException e){
throw new Exception(e.Message ,e);}

error=3;
}


The exception is pointing at error=2 location, and it was not at all handled
by try-catch ..

thanks&regards,


Hilton said:
OK WARNING, extremely hacky debug code:

int error = 0;

put an "error = 1", "error = 2" etc on alternating lines, then print error
when an exception gets thrown. Alternatively you can use VS to debug the
app, but sometimes good ol' fashion debugging works. This will tell you
what line the ArgumentException gets thrown.

What is an "Out of Memory, Argument Exception"? It is one or the other,
which one are you getting? Also, tell us exactly which line is throwing it
(see above).

Hilton


abcdef said:
Hi hilton,
Thanks for your reply. I implemented your suggestions and still getting
Argument Exception at the location I pointed out in my previous post.

Any ideas regarding this is so helpful.

thanks in advance,


Hilton said:
Oh, another thing that might help, is to read the stream into a byte[],
and
use that to do your new Bitmap.

Hilton


Hi,
I need help to handle out of memory, argument exception my .net CF 1.1
pocket pc application is throwing. Basically the following code will
accept
gps latitude and longitude coordinates as arguments and display image
returned from a mappoint webservice in a picturebox control and this
code
is
called repeatively until there were no Gps LAt/long coordinates.

And here is my code

private void GetMapImage(double latit,double longit)
{
try
{
double latit1,longit1;
latit1=latit;
longit1=longit;
Credentials();
LatLong myLatLong=new LatLong();
myLatLong.Latitude=latit;
myLatLong.Longitude=longit;
Location[] returnedLocations;
returnedLocations = findService.GetLocationInfo(myLatLong,
"MapPoint.NA",
null);
FindAddressSpecification myaddress= new FindAddressSpecification();
myaddress.DataSourceName="Mappoint.NA";
myaddress.InputAddress=returnedLocations[0].Address;
FindResults results =new FindResults();
results = findService.FindAddress(myaddress);
myViews[0] = results.Results0].FoundLocation.BestMapView.ByHeightWidth;

//Displaying Pushpins
Pushpin[] myPushpins = new Pushpin[1];
myPushpins[0] = new Pushpin();
myPushpins[0].IconDataSource="MapPoint.Icons";
myPushpins[0].IconName = "32";
myPushpins[0].Label = WrapText("You are here",10);
myPushpins[0].LatLong =myViews[0].CenterPoint;
myPushpins[0].ReturnsHotArea=true;
MapSpecification mapSpec = new MapSpecification();
Point MapDimensions=new Point();
mapSpec.DataSourceName ="MapPoint.NA";
mapSpec.Options=new MapOptions();
mapSpec.Options.ReturnType=MapReturnType.ReturnImage;
mapSpec.Options.Format=new ImageFormat();

mapSpec.Options.Format.MimeType="image/png";

mapSpec.Options.Format.Width=pbMyLocationMap.Width;
mapSpec.Options.Format.Height=pbMyLocationMap.Height;
mapSpec.Views = myViews;
mapSpec.Pushpins = myPushpins;

//Displaying the Map
MapImage[] mapImages =RenderService.GetMap(mapSpec);
pbMyLocationMap.Image= new Bitmap(new
System.IO.MemoryStreammapImages[0].MimeData.Bits));

}
catch(System.OutOfMemoryException ex)
{
throw new Exception(ex.Message,ex);
}
catch(System.ArgumentException ex)
{
throw new Exception(ex.Message,ex);
}

}----> Argument exception is showing at the following location. I didnt
get
whats going on. Don' know how to print the stack trace information in
.net
CF1.1 .net 2003 c#

And someone suggested not to load the bitmap in C# smart device
applications.

Anyone pls guide me.

Thanks so much in advance,
 
S

Sergey Bogdanov

Did you got exception in this part of code?

try
{
error=2;
}catch(System.ArgumentException e){
throw new Exception(e.Message ,e);}


This is really strange. Did you try to debug and step by step code? I
suppose that this exception throws somewhere else in your code.


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

Hi hilton,

After I implemented dispose method in my picturebox.image , my application
stopped throwing Out of Memory Exception.

I am now working towards the other exception ->Argument Exception that my
application is throwing..

And I debug the code as suggested, still didnt find useful information to
handle the exception.

Here is mycode again

rivate void GetMapImage(double latit,double longit)
{
int error=0;
try
{
double latit1,longit1;
latit1=latit;
longit1=longit;
Credentials();
LatLong myLatLong=new LatLong();
myLatLong.Latitude=latit;
myLatLong.Longitude=longit;
Location[] returnedLocations;
returnedLocations = findService.GetLocationInfo(myLatLong,
"MapPoint.NA", null);
FindAddressSpecification myaddress= new FindAddressSpecification();
myaddress.DataSourceName="Mappoint.NA";
myaddress.InputAddress=returnedLocations[0].Address;
FindResults results =new FindResults();
results = findService.FindAddress(myaddress);
myViews[0] = results.Results[0].FoundLocation.BestMapView.ByHeightWidth;

//Displaying Pushpins
Pushpin[] myPushpins = new Pushpin[1];
myPushpins[0] = new Pushpin();
myPushpins[0].IconDataSource="MapPoint.Icons";
myPushpins[0].IconName = "32";
myPushpins[0].Label = WrapText("You are here",10);
myPushpins[0].LatLong =myViews[0].CenterPoint;
myPushpins[0].ReturnsHotArea=true;

MapSpecification mapSpec = new MapSpecification();
Point MapDimensions=new Point();
mapSpec.DataSourceName ="MapPoint.NA";
mapSpec.Options=new MapOptions();
mapSpec.Options.ReturnType=MapReturnType.ReturnImage;
mapSpec.Options.Format=new ImageFormat();
mapSpec.Options.Format.MimeType="image/png";
mapSpec.Options.Format.Width=pbMyLocationMap.Width;
mapSpec.Options.Format.Height=pbMyLocationMap.Height;

mapSpec.Views = myViews;
mapSpec.Pushpins = myPushpins;

//Displaying the Map
MapImage[] mapImages =RenderService.GetMap(mapSpec);
Byte[] byteData = new Byte[0];
byteData = (Byte[])(mapImages[0].MimeData.Bits);
MemoryStream ms = new MemoryStream(byteData);
pbMyLocationMap.Image=new Bitmap(ms);
error=1;
}
//pbMyLocationMap.Image= new Bitmap(new
System.IO.MemoryStream(mapImages[0].MimeData.Bits));
catch(System.ArgumentException ex)
{
throw new Exception(ex.Message,ex);
}
try
{
error=2;
}catch(System.ArgumentException e){
throw new Exception(e.Message ,e);}

error=3;
}rivate void GetMapImage(double latit,double longit)
{
int error=0;
try
{
double latit1,longit1;
latit1=latit;
longit1=longit;
Credentials();
LatLong myLatLong=new LatLong();
myLatLong.Latitude=latit;
myLatLong.Longitude=longit;
Location[] returnedLocations;
returnedLocations = findService.GetLocationInfo(myLatLong,
"MapPoint.NA", null);
FindAddressSpecification myaddress= new FindAddressSpecification();
myaddress.DataSourceName="Mappoint.NA";
myaddress.InputAddress=returnedLocations[0].Address;
FindResults results =new FindResults();
results = findService.FindAddress(myaddress);
myViews[0] = results.Results[0].FoundLocation.BestMapView.ByHeightWidth;

//Displaying Pushpins
Pushpin[] myPushpins = new Pushpin[1];
myPushpins[0] = new Pushpin();
myPushpins[0].IconDataSource="MapPoint.Icons";
myPushpins[0].IconName = "32";
myPushpins[0].Label = WrapText("You are here",10);
myPushpins[0].LatLong =myViews[0].CenterPoint;
myPushpins[0].ReturnsHotArea=true;

MapSpecification mapSpec = new MapSpecification();
Point MapDimensions=new Point();
mapSpec.DataSourceName ="MapPoint.NA";
mapSpec.Options=new MapOptions();
mapSpec.Options.ReturnType=MapReturnType.ReturnImage;
mapSpec.Options.Format=new ImageFormat();
mapSpec.Options.Format.MimeType="image/png";
mapSpec.Options.Format.Width=pbMyLocationMap.Width;
mapSpec.Options.Format.Height=pbMyLocationMap.Height;

mapSpec.Views = myViews;
mapSpec.Pushpins = myPushpins;

//Displaying the Map
MapImage[] mapImages =RenderService.GetMap(mapSpec);
Byte[] byteData = new Byte[0];
byteData = (Byte[])(mapImages[0].MimeData.Bits);
MemoryStream ms = new MemoryStream(byteData);
pbMyLocationMap.Image=new Bitmap(ms);
error=1;
}
//pbMyLocationMap.Image= new Bitmap(new
System.IO.MemoryStream(mapImages[0].MimeData.Bits));
catch(System.ArgumentException ex)
{
throw new Exception(ex.Message,ex);
}
try
{
error=2;
}catch(System.ArgumentException e){
throw new Exception(e.Message ,e);}

error=3;
}rivate void GetMapImage(double latit,double longit)
{
int error=0;
try
{
double latit1,longit1;
latit1=latit;
longit1=longit;
Credentials();
LatLong myLatLong=new LatLong();
myLatLong.Latitude=latit;
myLatLong.Longitude=longit;
Location[] returnedLocations;
returnedLocations = findService.GetLocationInfo(myLatLong,
"MapPoint.NA", null);
FindAddressSpecification myaddress= new FindAddressSpecification();
myaddress.DataSourceName="Mappoint.NA";
myaddress.InputAddress=returnedLocations[0].Address;
FindResults results =new FindResults();
results = findService.FindAddress(myaddress);
myViews[0] = results.Results[0].FoundLocation.BestMapView.ByHeightWidth;

//Displaying Pushpins
Pushpin[] myPushpins = new Pushpin[1];
myPushpins[0] = new Pushpin();
myPushpins[0].IconDataSource="MapPoint.Icons";
myPushpins[0].IconName = "32";
myPushpins[0].Label = WrapText("You are here",10);
myPushpins[0].LatLong =myViews[0].CenterPoint;
myPushpins[0].ReturnsHotArea=true;

MapSpecification mapSpec = new MapSpecification();
Point MapDimensions=new Point();
mapSpec.DataSourceName ="MapPoint.NA";
mapSpec.Options=new MapOptions();
mapSpec.Options.ReturnType=MapReturnType.ReturnImage;
mapSpec.Options.Format=new ImageFormat();
mapSpec.Options.Format.MimeType="image/png";
mapSpec.Options.Format.Width=pbMyLocationMap.Width;
mapSpec.Options.Format.Height=pbMyLocationMap.Height;

mapSpec.Views = myViews;
mapSpec.Pushpins = myPushpins;

//Displaying the Map
MapImage[] mapImages =RenderService.GetMap(mapSpec);
Byte[] byteData = new Byte[0];
byteData = (Byte[])(mapImages[0].MimeData.Bits);
MemoryStream ms = new MemoryStream(byteData);
pbMyLocationMap.Image=new Bitmap(ms);
error=1;
}
//pbMyLocationMap.Image= new Bitmap(new
System.IO.MemoryStream(mapImages[0].MimeData.Bits));
catch(System.ArgumentException ex)
{
throw new Exception(ex.Message,ex);
}
try
{
error=2;
}catch(System.ArgumentException e){
throw new Exception(e.Message ,e);}

error=3;
}


The exception is pointing at error=2 location, and it was not at all handled
by try-catch ..

thanks&regards,


Hilton said:
OK WARNING, extremely hacky debug code:

int error = 0;

put an "error = 1", "error = 2" etc on alternating lines, then print error
when an exception gets thrown. Alternatively you can use VS to debug the
app, but sometimes good ol' fashion debugging works. This will tell you
what line the ArgumentException gets thrown.

What is an "Out of Memory, Argument Exception"? It is one or the other,
which one are you getting? Also, tell us exactly which line is throwing it
(see above).

Hilton


abcdef said:
Hi hilton,
Thanks for your reply. I implemented your suggestions and still getting
Argument Exception at the location I pointed out in my previous post.

Any ideas regarding this is so helpful.

thanks in advance,


:

Oh, another thing that might help, is to read the stream into a byte[],
and
use that to do your new Bitmap.

Hilton


Hi,
I need help to handle out of memory, argument exception my .net CF 1.1
pocket pc application is throwing. Basically the following code will
accept
gps latitude and longitude coordinates as arguments and display image
returned from a mappoint webservice in a picturebox control and this
code
is
called repeatively until there were no Gps LAt/long coordinates.

And here is my code

private void GetMapImage(double latit,double longit)
{
try
{
double latit1,longit1;
latit1=latit;
longit1=longit;
Credentials();
LatLong myLatLong=new LatLong();
myLatLong.Latitude=latit;
myLatLong.Longitude=longit;
Location[] returnedLocations;
returnedLocations = findService.GetLocationInfo(myLatLong,
"MapPoint.NA",
null);
FindAddressSpecification myaddress= new FindAddressSpecification();
myaddress.DataSourceName="Mappoint.NA";
myaddress.InputAddress=returnedLocations[0].Address;
FindResults results =new FindResults();
results = findService.FindAddress(myaddress);
myViews[0] = results.Results0].FoundLocation.BestMapView.ByHeightWidth;

//Displaying Pushpins
Pushpin[] myPushpins = new Pushpin[1];
myPushpins[0] = new Pushpin();
myPushpins[0].IconDataSource="MapPoint.Icons";
myPushpins[0].IconName = "32";
myPushpins[0].Label = WrapText("You are here",10);
myPushpins[0].LatLong =myViews[0].CenterPoint;
myPushpins[0].ReturnsHotArea=true;
MapSpecification mapSpec = new MapSpecification();
Point MapDimensions=new Point();
mapSpec.DataSourceName ="MapPoint.NA";
mapSpec.Options=new MapOptions();
mapSpec.Options.ReturnType=MapReturnType.ReturnImage;
mapSpec.Options.Format=new ImageFormat();

mapSpec.Options.Format.MimeType="image/png";

mapSpec.Options.Format.Width=pbMyLocationMap.Width;
mapSpec.Options.Format.Height=pbMyLocationMap.Height;
mapSpec.Views = myViews;
mapSpec.Pushpins = myPushpins;

//Displaying the Map
MapImage[] mapImages =RenderService.GetMap(mapSpec);
pbMyLocationMap.Image= new Bitmap(new
System.IO.MemoryStreammapImages[0].MimeData.Bits));

}
catch(System.OutOfMemoryException ex)
{
throw new Exception(ex.Message,ex);
}
catch(System.ArgumentException ex)
{
throw new Exception(ex.Message,ex);
}

}----> Argument exception is showing at the following location. I didnt
get
whats going on. Don' know how to print the stack trace information in
.net
CF1.1 .net 2003 c#

And someone suggested not to load the bitmap in C# smart device
applications.

Anyone pls guide me.

Thanks so much in advance,
 
Top