//縮放圖像文件
#include <opencv2/opencv.hpp>
using namespace std;
//隱藏控制臺窗口
#pragma comment(linker, "/subsystem:/"windows/" /entry:/"mainCRTStartup/"")
int main()
{
const char *pstrImageName = "airplane.jpg";
const char *pstrSaveImageName = "airplane縮放圖.jpg";
const char *pstrWindowsSrcTitle = "原圖";
const char *pstrWindowsDstTitle = "縮放圖";
double fScale = 2;//縮放倍數(shù)
CvSize czSize; //目標(biāo)圖像尺寸
//從文件中讀取圖像
IplImage *pSrcImage = cvLoadImage(pstrImageName, CV_LOAD_IMAGE_UNCHANGED);
IplImage *pDstImage = NULL;
//計算目標(biāo)圖像大小
czSize.width = pSrcImage->width * fScale;
czSize.height = pSrcImage->height * fScale;
//創(chuàng)建圖像并縮放
pDstImage = cvCreateImage(czSize, pSrcImage->depth, pSrcImage->nChannels);
cvResize(pSrcImage, pDstImage, CV_INTER_AREA);
//創(chuàng)建窗口
cvNamedWindow(pstrWindowsSrcTitle, CV_WINDOW_AUTOSIZE);
cvNamedWindow(pstrWindowsDstTitle, CV_WINDOW_AUTOSIZE);
//在指定窗口中顯示圖像
cvShowImage(pstrWindowsSrcTitle, pSrcImage);
cvShowImage(pstrWindowsDstTitle, pDstImage);
//等待按鍵事件
cvWaitKey();
//保存圖片
cvSaveImage(pstrSaveImageName, pDstImage);
cvDestroyWindow(pstrWindowsSrcTitle);
cvDestroyWindow(pstrWindowsDstTitle);
cvReleaseImage(&pSrcImage);
cvReleaseImage(&pDstImage);
return 0;
}