Метод MapPoint GetPictureFromObject - PullRequest
0 голосов
/ 13 июля 2009

Согласно документации MSDN :

метод GetPictureFromObject Возвращает изображение (объект Visual Basic Picture) текущего вида карты.

После копания я обнаружил, что этого объекта "Изображение", по-видимому, не существовало с VB6. Я думаю, что нет способа написать класс для маскировки под этот тип ... Или есть?

Ответы [ 2 ]

0 голосов
/ 26 октября 2015

Метод GetPictureFromObject () возвращает объект stdole.IPictureDisp COM.

Вот рабочий пример из http://www.mapping -tools.com / howto / mappoint / программирование / создавая 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);
}
}
0 голосов
/ 24 июля 2009

Похоже, что это проблема с , но нет симпатичного решения .

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;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...