Extract high quality MapPoint images using VB.NET
Takeaway: Microsoft MapPoint can display highly useful, customized information to all sorts of data consumers, from marketing and sales personnel to managers and decision-makers. But as Justin James demonstrates, extracting a quality MapPoint image requires some programmatic footwork via Microsoft Office Document Imaging and the .NET Framework.
The Microsoft MapPoint program is a great piece of software, with a wealth of capabilities above and beyond any of its Web-based competition, including its own online version. The ability to combine custom data with MapPoint's built-in datasets, such as Census Bureau demographics, allows the developer to display data in a way that is extremely helpful to marketing departments, salespeople, managers, executives, and other data consumers.
However, many of these users don't have access to the MapPoint software. In other cases, adding a map to a Web page, presentation, or even another piece of software would be useful. Sadly, Microsoft MapPoint, even when embedded as an ActiveX control and accessed programmatically via another Windows program, doesn't offer any methods to extract a high resolution image from it. But I'm going to show you how to accomplish that using pure, managed VB.NET code and Microsoft Office technologies. I'll be using Microsoft MapPoint, Microsoft Office Document Imaging, the .NET Framework's graphics capabilities, and the .NET Framework's process control functionality.
The challenge
The difficulty with getting an image file out of MapPoint seems to derive from a colossal mistake on Microsoft's part. Whether by design or omission, the MapPoint ActiveX control simply does not offer a Save As Image function. The closest alternative is to instruct the control to save the map as an HTML page, take the image file out of the resulting directory structure, and then delete the rest of the file created. This is a perfectly acceptable solution, provided that a 256-color, low resolution GIF file is acceptable to you and your users.
On a similar level, experimentation with copying the contents of the MapPoint ActiveX control to the clipboard shows that approach to be a possible solution. Unfortunately, this method poses some problems. First, changing the contents of the clipboard without the user being aware of it is a major usability flaw. Imagine if the software is performing many of these image saves, and the user starts working on a Word document. One moment, he's cutting a valuable paragraph to the clipboard. The next moment, he tries to paste that paragraph somewhere else--only to get a map instead. This is not very user friendly. Even worse, when I experimented with this technique I found that using it rapidly over the course of many iterations caused it to randomly fail for no explainable reason. There must be a better way.
The solution
The solution to this problem lies in a little-known part of the Microsoft Office System: Microsoft Office Document Imaging (MODI). MODI installs itself as part of the Microsoft Office 2003 System. It also functions as an installed printer, allowing you to print from any piece of software to it. It has its own document format, which functions similarly to PDF. The software can also save documents as TIFF files.
The MODI functionality is the key to this solution. By printing to the MODI printer and then taking control of the MODI process, you can save your images as extremely high resolution, high color depth images in the format of your choice, no less! That last part is extremely important; TIFF files tend to be extremely large, thanks to their lossless compression. Not every user has a good piece of software to view or manipulate TIFF files, and many pieces of software can't use them. Users are often forced to open a TIFF file in a graphics editing program, select the entire image, copy the selected area, and then paste it where they want. By being able to get the image into a format of your choice, you return control to the end user.
Drawbacks and difficulties
The major drawback to this technique is that you're going to be starting and stopping the MODI process for each image saved. In addition, printing to the MODI printer driver starts MODI but does not automatically close it. As a result, to make your code more user friendly, you must tap into the .NET Framework's methods for managing processes to shut down MODI after you're finished with it.
The code
To summarize, you need to perform the following steps to get the image out of MapPoint and into the format of your choice:
- Print to the MODI printer driver.
- Control MODI to convert the MODI document to TIFF format.
- Close MODI.
- Open the TIFF document and scale it as desired.
- Save the file to the desired filename and in the desired format (we'll assume a standard bitmap format).
- Remove the MODI document and the TIFF file.
Listing A shows the code to accomplish all of this. The only item to note is that the variable TempFiles is an instance of a custom class that manages temporary files and is assumed to be instantiated elsewhere in the application. The code for the class is included.
Print/View all Posts Comments on this article
|
|
|
|
|
|
White Papers, Webcasts, and Downloads
- Email Security and Archiving - Clearer in the Cloud Google The time is NOW for businesses and organizations of all sizes to implement ... Download Now
- Why Isn't Server Virtualization Saving Us More? A Few Small Changes May Dramatically Increase Your Efficiency VMware Ever wonder why your company isn't saving more from its server virtualization? Making a few small changes could dramatically increase your efficiency. Download Now
- The True Costs of Virtual Server Solutions VMware Discover ways to streamline and simplify your assessment of the total acquisition costs of a server virtualization environment. Download Now
- Building the Virtualized Enterprise with VMware Iinfrastructure VMware VMware virtualization software has been adopted by over 120,000 enterprise ... Download Now
- Five Steps to Determine When to Virtualize YourServers VMware Thinking of virtualizing the servers at your company? Use this step-by-step guide to determine when's the best time to make your big move. Download Now
Article Categories
- Security
- Security Solutions, IT Locksmith
- Networking and Communications
- E-mail Administration NetNote, Cisco Routers and Switches
- CIO and IT Management
- Project Management, CIO Issues, Strategies that Scale
- Desktops, Laptops & OS
- Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
- Data Management
- Oracle, SQL Server
- Servers
- Windows NT, Linux NetNote, Windows Server 2003
- Career Development
- Geek Trivia
- Software/Web Development
- Web Development Zone, Visual Basic, .NET

