根据msdn documentation:
GetPictureFromObject方法 返回当前地图视图的图片(Visual Basic图片对象)。
在挖掘之后,我发现这个“图片”对象显然自VB6以来就不存在了。我想没有办法写一个类来伪装成这种类型......或者在那里?
答案 0 :(得分:0)
这似乎是no pretty solution的问题。
public Image GetImage()
{
Image image = null;
object save = Clipboard.GetDataObject();
try
{
Application.ActiveMap.CopyMap();
IDataObject pict = Clipboard.GetDataObject();
string[] formats = pict.GetFormats();
foreach (string s in formats)
{
if (s.EndsWith(System.Windows.Forms.DataFormats.Bitmap))
{
image = (System.Drawing.Image)pict.GetData(System.Windows.Forms.DataFormats.Bitmap);
break;
}
}
}
finally
{
Clipboard.SetDataObject(save);
}
return image;
}
答案 1 :(得分:0)
GetPictureFromObject()方法返回 stdole.IPictureDisp COM对象。
以下是http://www.mapping-tools.com/howto/mappoint/programming/creating-map-images-in-c/
的工作示例 // Find the size of the PictureBox in pixels
// Then convert it into HIMETRIC units for MapPoint
// We perform the conversion using Inch2HIMETRIC (see above) and
// the system DPI values
// Note: MapPoint/VB6's definition of "long" is the same as C#'s definition for "int".
int iWidth, iHeight;
Graphics g = myPictureBox.CreateGraphics();
iWidth = (int)((double)myPictureBox.Width * Inch2HIMETRIC / g.DpiX);
iHeight = (int)((double)myPictureBox.Height * Inch2HIMETRIC / g.DpiY);
// GetPictureFromObject() is defined as a member of the MapPointUtilities class
MapPoint.MapPointUtilities myMapUtils = new MapPoint.MapPointUtilities();
// Create the Picture for the current map, as an stdole.IPictureDisp COM object
stdole.IPictureDisp ipicMap = (stdole.IPictureDisp)myMapUtils.GetPictureFromObject(myMap, iWidth, iHeight);
// Convert it to a (metafile) Drawing.Image using the OleCreateConverter defined above
System.Drawing.Image myImage = OleCreateConverter.PictureDispToImage(ipicMap);
// Copy the Drawing.Image to the Picture box
// Refresh and stretch for good measure
myPictureBox.Image = myImage;
myPictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
myPictureBox.Refresh();
// Save it as a PNG
// Although a GIF is capable of holding a MapPoint map, PNGs are generally prefered
myImage.Save(@"london2012.png", System.Drawing.Imaging.ImageFormat.Png);
以下是stdole.dll的元数据:
using System;
using System.Reflection;
using System.Runtime.InteropServices;
namespace stdole
{
[InterfaceType(2)]
[Guid("7BF80981-BF32-101A-8BBB-00AA00300CAB")]
[ComConversionLoss]
public interface IPictureDisp
{
[DispId(0)]
[ComAliasName("stdole.OLE_HANDLE")]
int Handle { get; }
[DispId(5)]
[ComAliasName("stdole.OLE_YSIZE_HIMETRIC")]
int Height { get; }
[DispId(2)]
[ComAliasName("stdole.OLE_HANDLE")]
int hPal { get; set; }
[DispId(3)]
short Type { get; }
[DispId(4)]
[ComAliasName("stdole.OLE_XSIZE_HIMETRIC")]
int Width { get; }
[DispId(6)]
void Render(int hdc, int x, int y, int cx, int cy, int xSrc, int ySrc, int cxSrc, int cySrc, IntPtr prcWBounds);
}
}