// T01051.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdarg.h>
#include <iostream>

#include <Windows.h>
#include <Psapi.h>
#include <time.h>
#include <atlimage.h>
using namespace std;

//#pragma comment(lib, "Psapi.lib")

static inline void hlogv(const char *format, va_list args)
{
char message[1024] = "";
int num = _vsprintf_p(message, 1024, format, args);
freopen("log.txt","w",stdout);
cout<<message<<endl;
freopen("CON", "w", stdout);
cout<<message<<endl;
}

void hlog(const char *format, ...)
{
va_list args;

va_start(args, format);
hlogv(format, args);
va_end(args);
}

void my_format(string &str_tmp)
{
int i = 0;
for(; str_tmp[i] ; i ++)
{
if(str_tmp[i] == ':')str_tmp[i] = '_';
//cout<<str_tmp[i];
}
//cout<<str_tmp<<endl;
str_tmp += ".bmp";
}

// int _tmain(int argc, _TCHAR* argv[])
// {
// // wchar_t base_path[260] = L"C:\Windows\system32\d3d9.dll";
// // HMODULE t = GetModuleHandleW(base_path);
// // cout<<t<<endl;
// // int k = 4;
// // char s[] = "111";
// // hlog(".%s..%d..",s,k);
// // cout<<1<<endl;
// // //string ss = "dfd";
// // time_t t = time(0);
// // char tmp[64] = "";
// // strftime( tmp, sizeof(tmp), "%Y%m%d%X",localtime(&t) );
// // string str_tmp = tmp;
// // //cout<<str_tmp.c_str()<<endl;
// // //cout<<ss<<endl;
// // my_format(str_tmp);
// // cout<<str_tmp.c_str()<<endl;
// getchar();
// return 0;
// }
bool CreateSmallPic(LPCTSTR szOldFileName, LPCTSTR szNewFilName , int resolution)
{
int WIDTH = 160 * resolution;
int HEIGHT = 160 * resolution;
CImage oldimg;
CImage newimg;
oldimg.Load(szOldFileName);
if(oldimg.IsNull())
return false;
int nWidth = WIDTH;
int nHeight = HEIGHT;

nWidth = oldimg.GetWidth();
nHeight = oldimg.GetHeight();

if(nWidth > WIDTH || nHeight > HEIGHT)
{
double dRatio = nWidth * 1.0 / nHeight;
if(nWidth > nHeight)
{
nWidth = WIDTH;
nHeight = nWidth / dRatio;
}
else
{
nHeight = HEIGHT;
nWidth = nHeight * dRatio;
}
}

if(!newimg.CreateEx(nWidth , nHeight , 24 , BI_RGB))
{
oldimg.Destroy();
return false;
}

int nPreMode = ::SetStretchBltMode(newimg.GetDC(), HALFTONE);
newimg.ReleaseDC();
oldimg.Draw(newimg.GetDC(), 0, 0, nWidth, nHeight, 0, 0, oldimg.GetWidth(), oldimg.GetHeight());
newimg.ReleaseDC();
::SetBrushOrgEx(newimg.GetDC(), 0, 0, NULL);
newimg.ReleaseDC();
::SetStretchBltMode(newimg.GetDC(), nPreMode);
newimg.ReleaseDC();

newimg.Save(szNewFilName);
newimg.Destroy();
oldimg.Destroy();

return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"hello"<<endl;
CImage oldmg;
CImage newimg;
wchar_t szOldFileName[] = L"D://0.jpg";
wchar_t szNewFilName[] = L"D://2.jpg";
bool res = CreateSmallPic((LPCTSTR)szOldFileName,(LPCTSTR)szNewFilName , 1000);
cout<<res<<endl;
getchar();
return 0;

}

 

posted on 2018-02-28 11:35  朽木の半夏  阅读(935)  评论(0编辑  收藏  举报