如何以编程方式调整图像大小 [英] How to resize image programatically

查看:185
本文介绍了如何以编程方式调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个应用程序,我以320 * 480格式存储相机拍摄的图像。但在加载此图像时,我想将图像调整为32 * 32或49 * 37.我可以让我知道如何加载图像,或者我们如何以相应的格式/尺寸存储相机拍摄的图像。 />


编辑

-----



我得到了即使我使用发布DC,退出时也会出错。 PFB代码

我正在尝试加载大图像并尝试将其调整为更小的尺寸。

 CImage img; 
CImage sm_img;
HRESULT res = img.Load(_T( D:\\bbb.png));

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);
// 接下来的两行测试图片控件上的图像。
// 输出的调色板错误,就像我的初始版本
HDC hdcpic = :: GetDC(hMyWindow); // hMyWindow - > of capCreateCaptureWindow

img.StretchBlt(hdcpic, 0 0 ,iNewWidth,iNewHeight,SRCCOPY);

sm_img.Save(_T( D:\\bbb1.png< /跨度>));
sm_img.ReleaseDC(); // 这里我发布DC但仍然
// 此代码在退出时出错
ReleaseDC(screenDC);



请告诉我可能是什么问题。



提前致谢。

解决方案

现有的问题解决方案可能符合您的需求。请看一下:如何使用CImage类调整位图大小 [ ^ ]。



问候,

- Manfred

Hi,

I have an application where I am storing images captured by camera in 320 * 480 format. But while loading this image I want to resize the image up to 32 * 32 OR 49 * 37. Can someone let me know how could we load the image or how could we store the images captured by camera in desired format / size.

EDIT
-----
Hi,
I am getting the error while exiting even if I use the release DC. PFB the code
I am trying to load big image and trying to resize it to smaller size.

CImage img;
CImage sm_img;
HRESULT res = img.Load(_T("D:\\bbb.png"));

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(hMyWindow);//hMyWindow --> of capCreateCaptureWindow

img.StretchBlt( hdcpic,0, 0, iNewWidth, iNewHeight, SRCCOPY);

sm_img.Save(_T("D:\\bbb1.png"));
sm_img.ReleaseDC(); // Here I release the DC but still
                        // this code is giving error while exiting
ReleaseDC(screenDC);


Please suggest me what could be the problem.

Thanks in advance.

解决方案

There is an already existing question with a solution that might fit your needs. Have a look at this please: How to use CImage class to resize a bitmap[^].

Regards,
— Manfred


这篇关于如何以编程方式调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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