初学者要求开始说明 [英] Beginner asks for starting instructions

查看:76
本文介绍了初学者要求开始说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,尊敬的CodeProject专业人士。



我需要创建一个显示我所在城市地图的对话框。



对话框应该有放大和缩小的按钮。



我需要的一个例子如下:
https://maps.google.com/



我只需要在对话框背景上粘贴地图,并根据用户的选择(无论用户是缩小还是缩小,或者最大化对话框)正确缩放它。



至于城市的地图图像,我可以通过名为ArcGis的软件获得我需要的东西,我可以将图片导出为位图,pgn,svg或其他东西。



我尝试将地图图像导出为bmp,并使用GDI将其绘制为对话框背景,但由于我使用了设备相关位图,因此图形质量很差,并且因为bmp文件使用有损数据压缩。



来说验证我的问题:



如何在对话框的背景上绘制地理地图,使用纯Win32 API正确缩放/缩放?



我应该使用哪种文件格式的地图? bmp,png还是svg?



可以用GDI完成,还是需要DirectDraw / GDI +等等?



我不能使用库,因为我有财务问题,我更愿意自己做(如果有一个免费的库可以帮助我考虑使用它)。



我知道问题很广泛,这就是为什么我要求指点,所以我可以开始了。



然后,我会问新的问题出现了具体问题。



我在Windows XP上工作,使用C ++和纯Win32 API。



谢谢。



问候。

Hello, respected professionals from CodeProject.

I need to create a dialog box that displays a map of my city.

Dialog box should have buttons for zoom in, and zoom out.

An example of what I need is closely illustrated here:
https://maps.google.com/

I just need to "paste" a map on dialogs background, and scale it properly, depending on users choice ( whether user zooms out or in, or dialog box is maximized ).

As for the city’s map image, I can get what I need from software called ArcGis, and I can export picture as bitmap, pgn, svg or something else.

I have tried exporting map image as bmp, and have used GDI to draw it as dialogs background, but quality of graphics was bad since I have used device dependent bitmaps, and since bmp files use lossy data compression.

To clarify my question:

How do you draw a geographical map on dialog’s background, scale/zoom it properly, using pure Win32 API ?

What file format should I use for map? bmp, png or svg ?

Can it be done with GDI or I need DirectDraw/ GDI+ or something else?

I can not use libraries, since I have financial issues, and I would prefer to do it myself ( if there is a free library that can help I will consider using it ).

I know that the question is broad, that is why I ask for pointers, so I can start.

Then, I will ask new questions as concrete problems occur.

I work on Windows XP, using C++ and pure Win32 API.

Thank you.

Regards.

推荐答案

这是一个相当冗长的问题,尤其是答案。

我现在很累,并会尽我所能解释。对于任何缺乏响应质量的道歉。



首先,BMP文件实际上使用无损压缩,因此它们是合适的(并且最容易处理.PNG文件可以是加载了GDI +,但这可能最好留给已经正常运行的应用程序.PNG的主要优点是它们在磁盘上的大小。



接下来,你可以轻松使用普通的'GDI来完成这项任务。除非加载GDI不支持的图像文件,否则不需要任何更重的重量(读取:除非使用几乎任何图像类型 - BMP是一个值得注意的例外)。



您可以使用StretchBlt进行缩放/绘图。

虽然您需要计算:

(a)部分你想要显示的图像

(b)纵横比和输出尺寸。(想想4:3电视上16:9内容的信箱显示,或黑边栏如果在16:9显示屏上显示4:3内容) - 您需要将图像置于一个轴上是,如果不是两个(当缩小很长的路时)





这里有一些来自我这里的旧项目的代码。第一个功能要求GDIplus已经初始化。虽然第二个没有保持正确的宽高比 - 它只是缩放图像以适合所选择的窗口。您需要更改它。



It's a rather lengthy question and more particularly, answer.
I'm tired right now and will explain the best I can. Apologies for any lack of quality of response.

Firstly, BMP files actually use lossless compression, so they are suitable (and the easiest to deal with. PNG files can be loaded with GDI+, but that's probably best left as an improvement to an already functioning application. The main advantage with PNGs being their size on disk.

Next, you can easily use plain ol' GDI for this task. No need for anything more heavy-weight, unless loading an image file not supported by GDI (read: unless using almost any image type - BMP being a notable exception).

You can use StretchBlt to do the scaling/drawing.
Though you will need to calculate:
(a) the portion of the image you'd like to display
(b) the aspect ratio and the output dimensions. (think letter-box display for 16:9 content on a 4:3 tv, or black side-bars if showing 4:3 content on a 16:9 display) - You need to center the image in one axis, if not both (when zoomed out a long way)


Here's some code from an old project I have here. The first function requires that GDIplus has already been initialized. While the second doesn't maintain the correct aspect ratio - it just scales the image to fit the chosen window. You'd need to change that.

// BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF
HBITMAP mLoadImg(WCHAR *szFilename)
{
    HBITMAP result=NULL;

    Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFilename,false);
    bitmap->GetHBITMAP(NULL, &result);
    delete bitmap;
    return result;
}

void displayImage(HWND dest, HBITMAP bmp)
{
    RECT myRect;
    BITMAP bm;
    HDC screenDC, memDC;
    HBITMAP oldBmp;

    screenDC = GetDC(dest);
    memDC = CreateCompatibleDC(screenDC);

    oldBmp = (HBITMAP)SelectObject(memDC, bmp);
    GetObject(bmp, sizeof(bm), &bm);
    GetClientRect(dest, &myRect);

    StretchBlt(screenDC, 0,0,myRect.right,myRect.bottom, memDC, 0,0,bm.bmWidth,bm.bmHeight, SRCCOPY);

    SelectObject(memDC, oldBmp);
    ReleaseDC(dest, screenDC);
    DeleteDC(memDC);
}





我通常在main()中初始化GDI +,如下所示:



I generally init GDI+ in main(), like this:

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    hInst = hInstance;
    InitCommonControls();
    // The user interface is a modal dialog box
    DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
    Gdiplus::GdiplusShutdown(gdiplusToken);
}


如果你想放大,那么你需要一个非常高分辨率的图像。由于加载这样的图像可能非常慢,您可能需要使用不同分辨率的图像(例如在Google地图中)并根据缩放系数选择适当的图块。



您应该使用与设备无关的位图来确保正确显示图像。无论如何,如果图像在其他应用程序中正确显示,应该很容易弄清楚程序是否有问题。
If you want to zoom in, then you neeed a very high resolution image. Since loading such an image can be very slow, you might need to have images at differnt resolution (like in Google Maps) and select appropriate tiles to display depending on the zoom factor.

You should probably used device independent bitmaps to ensure that the image are correctly displayed. Anyway, it should be easy to figure out if you program have a problem if the image is properly display in other applications.


这篇关于初学者要求开始说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆