如何使用CImage类调整位图的大小 [英] How to use CImage class to resize a bitmap
本文介绍了如何使用CImage类调整位图的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用以下代码调整保存在文件中的位图的大小
I want to resize a bit picture saved in a file with the following code
CImage img;
CImage sm_img;
img.Load(FileName);
sm_img.Create(80,60,img.GetBPP(),
HDC sm_hdc = sm_img.GetDC();
img.StretchBlt(sm_hdc,0,0,80,60,SRCCOPY);
sm_img.Save(sjpgFileName);
img.Detach();
由于颜色丢失,结果很糟糕.我来宾,我们需要为变量 sm_img 设置som属性,但不知道如何.
The result is bad as colors are lost. I guest we need to set som attributes for the variable sm_img but don''t know how. Can you help me, please !
推荐答案
例如,请参见: [ ^ ].
See, for instance, here: "Scaling CImage"[^].
您无需创建DC(pMDC).只需使用sm_img(sm_img.GetDC())中的DC:
You don''t need to create a DC (pMDC). Just use the DC from sm_img (sm_img.GetDC()):
CImage img;
CImage sm_img;
HRESULT res = img.Load(jpgFileName);
CDC *screenDC = GetDC();
int iNewWidth = 80;
int iNewHeight = 60;
sm_img.Create(iNewWidth, iNewHeight,32);
SetStretchBltMode(sm_img.GetDC(),COLORONCOLOR);
img.StretchBlt(sm_img.GetDC(),0, 0, iNewWidth, iNewHeight, SRCCOPY);
// The next two lines test the image on a picture control.
// The output has wrong color palette, like my initial version
HDC hdcpic = ::GetDC(m_ClipPreview.m_hWnd);
img.StretchBlt( hdcpic,0, 0, iNewWidth, iNewHeight, SRCCOPY);
sm_img.Save(jpgFileName);
ReleaseDC(screenDC);
希望对您有帮助
我加了一行
Hope it helps
I added one line
sm_img.ReleaseDC();
最后避免退出函数时出错
in the end to avoid error when exiting the function
这篇关于如何使用CImage类调整位图的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文