首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MapPoint GetPictureFromObject方法

MapPoint GetPictureFromObject方法
EN

Stack Overflow用户
提问于 2009-07-13 13:21:03
回答 2查看 352关注 0票数 0

根据msdn 文档

GetPictureFromObject方法返回当前地图视图的图片(Visual对象)。

在四处搜寻之后,我发现这个“图片”对象显然从VB6开始就不存在了。我想没有办法写一个类来伪装成这种类型.还是真的有?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-07-24 08:17:11

这似乎是没有很好的解决方案的一个问题。

代码语言:javascript
复制
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;
}
票数 0
EN

Stack Overflow用户

发布于 2015-10-26 16:18:56

GetPictureFromObject()方法返回一个stdole.IPictureDisp COM对象。

下面是来自http://www.mapping-tools.com/howto/mappoint/programming/creating-map-images-in-c/的一个工作示例

代码语言:javascript
复制
            // 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的元数据:

代码语言:javascript
复制
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);
}
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1119408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档