I belive BinaryData in SQL is nothing but BLOB esri field format.
If so, the elements can be stored into BLOB fields using IPersistStream interface. You can look for an article to find a way to store the data usingIMemoryBlobStream and
IPersistStream interfaces.
public class Test { IStream stream; IMap myMap; void Save() { IPersistStream perStream; IMemoryBlobStream memoryStream = new MemoryBlobStreamClass(); stream = memoryStream as IStream; perStream = (IPersistStream ) myMap ; perStream.Save(stream, 0); } void Load() { IMemoryBlobStream memoryStream = new MemoryBlobStreamClass(); IPersistStream pstm = new MapClass(); pstm.Load(stream); **// throw error: Error HRESULT E_FAIL has been returned from a call to a COM component.** myMap = (IMap)pstm; } }
void Save (AxPageLayoutControl pageControl) { IPersistStream perStream; IMemoryBlobStream memoryStream = new MemoryBlobStreamClass(); IGraphicsContainer graphicsContainer = pageControl.ActiveView.GraphicsContainer; graphicsContainer.Reset(); IElement pElement = graphicsContainer.Next(); while (pElement != null) { if (pElement is IMapFrame) { perStream = (IPersistStream)pElement ; perStream.Save(memoryStream, 0); memoryStream.SaveToFile("C:/image.bmp"); break; } pElement = graphicsContainer.Next(); } } void Load (AxPageLayoutControl pageControl) { IPersistStream perStream; IMemoryBlobStream memoryStream = new MemoryBlobStreamClass(); IGraphicsContainer graphicsContainer = pageControl.ActiveView.GraphicsContainer; graphicsContainer.Reset(); IElement pElement = graphicsContainer.Next(); while (pElement != null) { if (pElement is IMapFrame) { memoryStream.LoadFromFile("C:/image.bmp"); perStream = (IPersistStream)pElement; perStream.Load(memoryStream); IMapFrame frame = new MapFrameClass(); frame = (IMapFrame)perStream; pElement = (IElement)frame; break; } pElement = graphicsContainer.Next(); } pageControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
Hi,
I found out the way to store elements (of a MapFrame) into Image and load again by using the below codes:void Save (AxPageLayoutControl pageControl) { IPersistStream perStream; IMemoryBlobStream memoryStream = new MemoryBlobStreamClass(); IGraphicsContainer graphicsContainer = pageControl.ActiveView.GraphicsContainer; graphicsContainer.Reset(); IElement pElement = graphicsContainer.Next(); while (pElement != null) { if (pElement is IMapFrame) { perStream = (IPersistStream)pElement ; perStream.Save(memoryStream, 0); memoryStream.SaveToFile("C:/image.bmp"); break; } pElement = graphicsContainer.Next(); } } void Load (AxPageLayoutControl pageControl) { IPersistStream perStream; IMemoryBlobStream memoryStream = new MemoryBlobStreamClass(); IGraphicsContainer graphicsContainer = pageControl.ActiveView.GraphicsContainer; graphicsContainer.Reset(); IElement pElement = graphicsContainer.Next(); while (pElement != null) { if (pElement is IMapFrame) { memoryStream.LoadFromFile("C:/image.bmp"); perStream = (IPersistStream)pElement; perStream.Load(memoryStream); IMapFrame frame = new MapFrameClass(); frame = (IMapFrame)perStream; pElement = (IElement)frame; break; } pElement = graphicsContainer.Next(); } pageControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
But, I am finding a way to convert IPersistStream or IMemoryBlobStream to byte[] (binary format), so I can store in the SQL Server and load it later.
Are there anyone know this ?
Thanks and regards,
so i first save the map to a file, and then save the file into the database, it was the workaround that i found to solve it.
but i cannot save the map directly into the database
IPersistStream perStream; IXMLStream xmlStream = new XMLStreamClass(); perStream = (IPersistStream)pElement; IStream stre = (IStream)xmlStream; perStream.Save(stre, 0); byte[] map = xmlStream.SaveToBytes(); // insert "map" into database //.....
Reading your code, you are trying to save a bitmap of the map (a graphic representation) not the map per se....aren't you?