CImage修改图片尺寸

CImage修改图片尺寸boolResizePicture(CStringstrSource,CStringstrTarget){intWIDTH=70;intHEIGHT=70;CImageoldimg;CImagenewimg;oldimg.Load(strSource);if(oldimg.IsNull())…

大家好,又见面了,我是你们的朋友全栈君。


bool ResizePicture(CString strSource, CString strTarget)
{
    int WIDTH = 70;
    int HEIGHT = 70;
    CImage oldimg;
    CImage newimg;
    oldimg.Load(strSource);
    if (oldimg.IsNull())
        return false;
    int nWidth = 0;
    int nHeight = 0;

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

    if (nWidth > WIDTH || nHeight > HEIGHT)
    {
        double dRatio = nWidth * 1.0 / nHeight;
        if (nWidth > nHeight)
        {
            nWidth = WIDTH;
            nHeight = (int)(nWidth / dRatio);
        }
        else
        {
            nHeight = HEIGHT;
            nWidth = (int)(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(strTarget);
    newimg.Destroy();
    oldimg.Destroy();

    return true;
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/149152.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • springboot源码解析详细版

    springboot源码解析详细版springboot源码解析(转)SpringBoot的入口类@SpringBootApplicationpublicclassStartupApplication{publicstaticvoidmain(String[]args){SpringApplication.run(StartupApplication.class,args)…

    2022年5月1日
    56
  • linux获取root权限命令_linux最高权限获取命令

    linux获取root权限命令_linux最高权限获取命令Linux上一切皆文件,不管什么程序,读取文件就能获取一个UUID.Linux内核提供有UUID生成接口:cat/proc/sys/kernel/random/uuid  获取系统uuiddmidecode-ssystem-uuid|tr’A-Z”a-z’  转载于:https://www.cnblogs.com/navysummer/…

    2022年8月10日
    10
  • 禁止计算机更新,彻底禁止win10自动更新方法

    禁止计算机更新,彻底禁止win10自动更新方法现在基本每个小伙伴都用上Windows10的电脑,Windows10每隔一段时间会进行更新补丁,这个时候显得格外烦恼,很多用户都想要关掉,借助一些小工具来实现,但往往会发现,自动更新就像打不死的小强,不管怎么关闭,之后还是会自动更新,让用户非常不爽,win10关闭自动更新已经成为众多用户的难题,所以很多用户来问我怎么才可以把win10永久关闭自动更新,接下来,我就给大家介绍彻底禁止win10自动更…

    2022年5月4日
    82
  • dede list列表页和文章页分别使用if else

    dede list列表页和文章页分别使用if else

    2021年9月24日
    43
  • python语法(二)——截取字符串的方法详解

    python语法(二)——截取字符串的方法详解下面是基于python2+版本;python3+print输出的内容要加括号str=’0123456789’printstr[0:3]#截取第一位到第三位的字符printstr[:]#截取字符串的全部字符printstr[6:]#截取第七个字符到结尾printstr[:-3]#截取从头开始到倒数第三个字符之前printstr[2]#截取第三个字符printstr[-1]…

    2022年5月10日
    43
  • 树莓派是什么_树莓派gpio

    树莓派是什么_树莓派gpio给树莓派换了阿里云的镜像源后,更新软件源,出现了`GPGerror`问题。

    2022年10月13日
    5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号