CDC * screendc = getdc();提供错误“类型的值”HDC“不能用于初始化类型为“CDC *”的实体。 [英] CDC *screendc = getdc(); providing error "a value of type "HDC" cannot be used to initialize an entity of type "CDC *"

查看:664
本文介绍了CDC * screendc = getdc();提供错误“类型的值”HDC“不能用于初始化类型为“CDC *”的实体。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我遇到了一段用于扩展图像的代码问题。我在这里找到了一段代码缩放CImage [ ^ ]。我的问题是行CDC * screenDC = GetDC();给出错误类型值HDC不能用于初始化CDC *类型的实体。我不确定如何修复它作为我的所有帐户它应该正常工作和大多数其他解决方案以此为例。



这是代码

  int  iNewWidth =  2048 ; 
int iNewHeight = 2048 ;

CImage图像;
image.Load(_T( C:\\Image.jpg));

CDC * screenDC = GetDC(); // 提供错误的部分
CDC * pMDC = CDC;
pMDC-> CreateCompatibleDC(screenDC);

CBitmap * pb = new CBitmap;
pb-> CreateCompatibleBitmap(screenDC,iNewWidth, iNewHeight);

CBitmap * pob = pMDC-> SelectObject(pb);
image.StretchBlt(pMDC-> m_hDC, 0 0 ,iNewWidth,iNewHeight, 0 0 ,image.GetWidth(),image.GetHeight(),SRCCOPY);
pMDC-> SelectObject(pob);

CImage new_image;
new_image.Attach((HBITMAP)(* pb));
new_image.Save(_T( c:\\NewImage.jpg) );
new_image.Detach();
ReleaseDC(screenDC);





谢谢



< b>我尝试了什么:



删除此行会导致图像缩放后显示为黑色。

解决方案

我猜你不是CWnd派生类,它是一个成员函数。



因为这个原因是一个函数< a href =https://msdn.microsoft.com/library/953f9btx.aspx> FromHandle()可用。



阅读更多关于图形和示例代码,以填补您的知识空白。 ; - )

Hi I'm having issue with a piece of code meant to scale an image.I found a peice of code to do this here Scaling CImage[^]. My problem is that the line CDC *screenDC = GetDC(); gives the error "a value of type "HDC" cannot be used to initialize an entity of type "CDC *". I'm not really sure how to fix it as my all accounts it should be working correctly and most of the other solutions offer this as an example.

Here is the code

int iNewWidth = 2048;
	int iNewHeight = 2048;

	CImage image;
	image.Load(_T("C:\\Image.jpg"));
	
	CDC *screenDC = GetDC(); //Section that gives error
	CDC *pMDC = new CDC;
	pMDC->CreateCompatibleDC(screenDC);

	CBitmap *pb = new CBitmap;
	pb->CreateCompatibleBitmap(screenDC, iNewWidth, iNewHeight);

	CBitmap *pob = pMDC->SelectObject(pb);
	image.StretchBlt(pMDC->m_hDC,0, 0, iNewWidth, iNewHeight, 0, 0, image.GetWidth(), image.GetHeight(), SRCCOPY);
	pMDC->SelectObject(pob);
	
	CImage new_image;
	new_image.Attach((HBITMAP)(*pb));
	new_image.Save(_T("c:\\NewImage.jpg"));
	new_image.Detach();
	ReleaseDC(screenDC);



Thanks

What I have tried:

Removing this line causes the image to be black after it has been scaled.

解决方案

I guess that you arent in a CWnd derived class, where it is a member function.

For that reason is a function FromHandle() available.

Read some more about graphics and sample code to fill you knowledge gaps. ;-)


这篇关于CDC * screendc = getdc();提供错误“类型的值”HDC“不能用于初始化类型为“CDC *”的实体。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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