在MFC中缩放图像时出现问题 [英] Problem in Zooming an image in MFC

查看:86
本文介绍了在MFC中缩放图像时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家好,

我刚刚开始使用MFC进行编程,但仍然不熟悉它的类!

我使用GDAL库加载了一个多光谱图像。我想在我的程序中添加缩放功能。

首先,我使用以下代码将我的图像显示到客户区:

Hi folks,
I've just started programming using MFC and still not familiar with its classes!
I have loaded a multispectral images using GDAL library. I want to add zooming function into my program.
First, I display my image into client area using this code:

::SetDIBitsToDevice(pDC->GetSafeHdc(), 0, 0,
        nXSize, nYSize,
        0, 0,
        0, nYSize,
        m_DispImage,
        &btminf,
        DIB_RGB_COLORS);



图像大于客户区。我希望用户按下zoomtofit按钮,图像将适合客户区。我以新格式计算了图像的大小,并使用此代码执行任务:


The image is larger than the client area. I want the user to push the zoomtofit button and the image would be fitted to the client area. I calculated the size of the image in new format and use this code to do the task:

HDC hdcMem=CreateCompatibleDC(pDC->GetSafeHdc());
	::StretchBlt (hdcMem,
		0, 0,
		XSize, YSize,
		pDC->GetSafeHdc(),
		0, 0,
		nXSize, nYSize,
		SRCCOPY ); 



但是客户区没有显示任何内容。你知道问题是什么吗?


But nothing is shown in the client area. Do you know what is the problem?

推荐答案

当你使用CreateCompatibleDC创建一个内存设备上下文时,你必须选择一个内存位图给它一个画布来绘制到。默认情况下,内存DC将具有单个像素黑白位图。
When you create a memory device context with CreateCompatibleDC you have to select a memory bitmap into it to give it a canvas to draw onto. By default a memory DC will have a single pixel black and white bitmap.


这篇关于在MFC中缩放图像时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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