hanneslarsson
03-17-2008, 08:20 AM
How do I set a custom pushpin symbol from a in memory Bitmap image?
I know that I can load an image like this:
Symbol muSymbol = m_MapApp.ActiveMap.Symbols.Add("c:\myImage.bmp");
pin.Symbol = muSymbol.ID;
But is there a way to set the symbol from an bitmap image in the compiled resources? or is there a way to add a bitmap directly like:
Bitmap myBitmap = new Bitmap("c:\myImage.bmp");
Symbol muSymbol = m_MapApp.ActiveMap.Symbols.Add(myBitmap);
pin.Symbol = muSymbol.ID;
lfdmike
03-17-2008, 09:57 AM
You may be able to use a memory stream to do this.
hanneslarsson
03-17-2008, 09:59 AM
Do you have any example code when a memory stream is used?
Thanks!
Wilfried
03-18-2008, 09:26 AM
Hi,
I think it has to be a disk file. Eventually you can speed up using a ram disk.
hanneslarsson
03-19-2008, 01:15 AM
So there is no way to compile the image into the projects resources and then fetch it from there into my mappoint object???
lfdmike
03-19-2008, 08:58 AM
Do you have any example code when a memory stream is used?
Unfortunately I do not, I have not done any mapplications that have needed it. Memory Streams are an I/O Class, and can be used for the moving of images to/from databases, and I use them for websites. You may want to look at it over at MSDN (http://msdn2.microsoft.com/en-us/library/system.io.memorystream.aspx)
Bitmap myBitmap = new Bitmap("c:\myImage.bmp");
MemoryStream myStream = new MemoryStream();
myBitmap.Save(myStream, ImageFormat.bmp);
is all good code. now you just need to get that into your symbol variable
Wilfried
03-19-2008, 09:45 AM
Hi,
Maybe create a mapped file ? This is a file resident in memory. Normally windows API has same functions for all types of IO, so possible it works with mappoint as well. See http://msdn2.microsoft.com/en-us/library/aa366551(VS.85).aspx for some example.
On the other hand I think it is much more simple to keep all bitmaps in resource of your application, save them to a real file, import in mappoint, and "I think" you can delete them afterwards (not sure).
Did this just yesterday.
My problem was that my bitmap was a 32 bit image (Bitmap bm) and the pushpins have to be 24 bit or smaller. I am tracking trailers, hence the notation of TrailerName. You use your own names, of course.
So, that is the code that I have here ....
Bitmapbitdump = newBitmap(bm.Width, bm.Height, PixelFormat.Format24bppRgb);
for (intx = 0; x < bm.Width; x++)
{
for (inty = 0; y < bm.Height; y++)
{
Colorc = bm.GetPixel(x, y);
bitdump.SetPixel(x, y, Color.FromArgb(c.R, c.G, c.B));
}
}
Stringpath = objMap.Parent.DefaultFilePath;
bitdump.Save(path + "/" + TrailerName + ".bmp", ImageFormat.Bmp);
MapPoint.Symbolsym = objMap.Symbols.Add(TrailerName + ".bmp");
MapPoint.Locationloc = objMap.GetLocation(Latitude, Longitude, 0);
MapPoint.Pushpinpin = objMap.AddPushpin(loc, TrailerName);
pin.Symbol = sym.ID;
I create a new 24 bit bitmap and do the easy and long way to copy the bits from the source bitmap to my target. There may be a better way but I wanted to get the show going and didn't feel like reading and researching for something else.
Anyway, having built the new bitmap, I found that it had to be saved in the MapPoint folder structure. That is the need for the path variable.
Save the bitmap and re-read it into a symbol.
Assign the symbol to the pushpin
Dennis