• 修改图片大小 分辨率


    // 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:Windowssystem32d3d9.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;

    }

  • 相关阅读:
    1.文件I/O
    sqlite-按日期分组,根据日期查询详细内容
    sqlite-在数据库中创建默认时间
    Git-git 忽略 IntelliJ .idea文件
    重启猫(modem)的方法
    从TP、FP、TN、FN到ROC曲线、miss rate、行人检测评估
    畅所欲言第1期
    使用属性表:VS2013上配置OpenCV
    关于OOM那些事儿
    深度学习之江湖~那些大神们
  • 原文地址:https://www.cnblogs.com/clover-xuqi/p/8482733.html
Copyright © 2020-2023  润新知