用了好几个软件都不好用.

要么不能翻转PNG, 要么翻转之后没有透明度了.

基本上全是图形界面, 要鼠标批量拖放.

所以, 还是自己动手, 写一个批量png翻转工具.

 #include <iostream>
 #include <vector>
 #include <list>
 #include <string>
 #include <iterator>
 #include <functional>
 #include <memory>
 #include <fstream>
 #include <sstream>

 #include <Shlwapi.h>
 #include <Windows.h>
 #include <gdiplus.h>

 #pragma comment(lib, "gdiplus.lib")
 #pragma comment(lib, "Shlwapi.lib")

 enum {
     eHreverse,
     eVreverse
 };

 inline std::wstring getDirectory(const std::wstring &fullname)
 {
     auto findIndex = fullname.find_last_of('\\');
     return findIndex != std::wstring::npos
         ? fullname.substr(, findIndex + ) : std::wstring();
 }

 inline std::wstring getFullName(const std::wstring &fullname)
 {
     auto findIndex = fullname.find_last_of('\\');
     return findIndex != std::wstring::npos
         ? fullname.substr(findIndex + ) : std::wstring();
 }

 template <class T1, class T2>
 inline T1 parseTo(const T2 &t)
 {
     static std::wstringstream sstream;
     T1 r;
     sstream << t;
     sstream >> r;
     sstream.clear();
     return r;
 }

 CLSID findCLSID(const std::wstring &format)
 {
     CLSID clsid = {  };
     auto num = 0u;
     auto size = 0u;
     Gdiplus::GetImageEncodersSize(&num, &size);
     )
     {
         auto pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size));
         if (pImageCodecInfo != nullptr)
         {
             GetImageEncoders(num, size, pImageCodecInfo);

             ; j< num; ++j)
             {
                 if (format == pImageCodecInfo[j].MimeType)
                 {
                     clsid = pImageCodecInfo[j].Clsid;
                     break;
                 }
             }
             free(pImageCodecInfo);
         }
     }
     return clsid;
 }

 void forEachFileList(
     const std::wstring &fileListName,
     const std::function<void (const std::wstring &)> &handler)
 {
     std::wifstream ifile(fileListName);
     if (ifile)
     {
         std::wstring fileName;
         while (std::getline(ifile, fileName))
         {
             handler(fileName);
         }
         ifile.close();
     }
 }

 int createSaveDirector(const std::wstring &director)
 {
     auto result = true;
     if (!PathFileExists(director.c_str()))
     {
         result = CreateDirectory(director.c_str(), nullptr) != ;
     }
     return result;
 }

 void saveImage(Gdiplus::Bitmap *pImage, const CLSID &clsid, const std::wstring &saveFile)
 {
     auto director = getDirectory(saveFile);
     director.append(L"\\save\\");
     if (createSaveDirector(director))
     {
         director.append(getFullName(saveFile));
         std::wcout
             << L"save image file: "
             << director << std::endl;
         pImage->Save(director.c_str(), &clsid);
     }
 }

 void flipImage(const std::wstring &fileName, const CLSID &clsid, int type)
 {
     Gdiplus::Bitmap image(fileName.c_str());
     if (image.GetLastStatus() == Gdiplus::Ok)
     {
         auto rotate = type == eHreverse
             ? Gdiplus::Rotate180FlipY
             : Gdiplus::Rotate180FlipX;
         image.RotateFlip(rotate);
         saveImage(&image, clsid, fileName);
     }
 }

 void run(const std::wstring &fileList, int type)
 {
     u_long token;
     Gdiplus::GdiplusStartupInput input;
     Gdiplus::GdiplusStartup(&token, &input, nullptr);
     {
         auto clsid = findCLSID(L"image/png");
          || clsid.Data2 !=  || clsid.Data3 != )
         {
             forEachFileList(
                 fileList,
                 std::bind(flipImage, std::placeholders::_1, clsid, type));
         }
     }
     Gdiplus::GdiplusShutdown(token);
 }

 int wmain(int argn, wchar_t *argc[])
 {
     std::locale(std::locale::global(std::locale("chs")));
     std::wcout << argn << std::endl;
     )
     {
         std::wcout
             << L"参数格式:\n"
             << L"    imglist.txt type\n"
             << L"    type:\n"
             << L"        0 水平翻转\n"
             << L"        1 垂直翻转"
             << std::endl;
     }
     else
     {
         run(argc[], parseTo<]));
     }
     std::wcout << L"run done." << std::endl;
     std::wcin.get();
     ;
 }

下载地址

使用说明:

  一个包含被翻转图片路径列表的文本文件, 一个翻转类型(控制x, y轴翻转)

第一个参数可以参考我上一篇随笔:  批量缩放PNG图片.

批量翻转PNG图片的更多相关文章

  1. 批量下载网站图片的Python实用小工具

    定位 本文适合于熟悉Python编程且对互联网高清图片饶有兴趣的筒鞋.读完本文后,将学会如何使用Python库批量并发地抓取网页和下载图片资源.只要懂得如何安装Python库以及运行Python程序, ...

  2. Zencart批量删除无图片产品

    Zencart批量删除无图片产品 2012-04-23 07:26:18|  分类: 默认分类 |字号 订阅 转自 http://zhongjia33.blog.163.com/blog/#m=0   ...

  3. 批量下载网站图片的Python实用小工具(下)

    引子 在 批量下载网站图片的Python实用小工具 一文中,讲解了开发一个Python小工具来实现网站图片的并发批量拉取.不过那个工具仅限于特定网站的特定规则,本文将基于其代码实现,开发一个更加通用的 ...

  4. [转]解决Magento批量导入带图片的商品的问题

    本文转自:http://www.phpstudio.info/show-121-791-1.html 一般来说,Magento后台管理里的CSV批量导入,可以解决我们商品批量上传的大部分问题,我们只要 ...

  5. python多线程批量下载远程图片

    python多线程使用场景:多线程采集, 以及性能测试等 . 数据库驱动类-简单封装下 mysqlDriver.py #!/usr/bin/python3 #-*- coding: utf-8 -*- ...

  6. 自己积累的一些Emgu CV代码(主要有图片格式转换,图片裁剪,图片翻转,图片旋转和图片平移等功能)

    using System; using System.Drawing; using Emgu.CV; using Emgu.CV.CvEnum; using Emgu.CV.Structure; na ...

  7. 批量缩放PNG图片.

    最近需要缩放N多图片, 找遍了互联网也没有找到方便使用的批量缩放工具.. 趁着周末写一个练手.. #include <iostream> #include <vector> # ...

  8. word2013怎样批量重设图片和大小?(转)

    https://www.zhihu.com/question/52908434/answer/132934213 点击视图,宏,查看宏,任意输入一个宏名,创建,清空框内内容,复制以下代码粘贴,保存. ...

  9. Android之批量加载图片OOM问题解决方案

    一.OOM问题出现的场景和原因 一个好的app总少不了精美的图片,所以Android开发中图片的加载总是避免不了的,而在加载图片过程中,如果处理不当则会出现OOM的问题.那么如何彻底解决这个问题呢?本 ...

随机推荐

  1. 【转】【opencv】仿射变换

    仿射变换 目标 在这个教程中你将学习到如何: 使用OpenCV函数 warpAffine 来实现一些简单的重映射. 使用OpenCV函数 getRotationMatrix2D 来获得一个  旋转矩阵 ...

  2. 在html使用a标签 直接下载图片 不通过后台实现直接下载

    由于a标签在HTML中链接图片会被识别并打开到网页上 如果想下载这个图片的话 就需要连接到后台读取文件并生成一个头信息下载.不过可以先给a标签加上一个download属性即可直接下载了. <a ...

  3. Expression Blend 4 激活码

    Expression Blend 4 激活码: 6WDDQ-K7D4F-GQGF4-2VYBJ-8K6MB

  4. MISCONF Redis is configured to save RDB snapshots

    今天客户突然反馈用我们的api出现了下面的这个错误 MISCONF Redis is configured to save RDB snapshots, but is currently not ab ...

  5. Java分布式优秀资源集合

    这里充分尊重原作者的版本,学习了知识要感激原博主 Runnable.Callable.Executor.Future.FutureTask关系解读 http://blog.csdn.net/zhang ...

  6. Android中使EditText失去焦点,edittext禁止弹出键盘[转]

    转自http://www.cnblogs.com/yejiurui/archive/2013/01/02/2841945.html 在我们的应用中,有时候一进入一个页面, EditText默认就会自动 ...

  7. 谷歌google搜索打不开、谷歌gmail邮箱及相关服务无法登录的解决的方法

    歌打不开 google打不开,与中国大陆封杀有关,可是主要是由于近期googleserver在全球范围内又一次进行了布局调整. 解决的方法是仅仅要改动用户本地计算机hosts文件就能够了. 一.Win ...

  8. SCADESuite嵌入式软件基于模型的开发

    SCADE Suite®产品是针对高安全性嵌入式软件的基于模型的开发环境 SCADE Suite是高安全性嵌入式软件的开发标准,其应用领域涵盖航空.国防.轨道交通.能源和重工业.专为最高等级的质量和安 ...

  9. iOS中保证线程安全的几种方式与性能对比

    来源:景铭巴巴 链接:http://www.jianshu.com/p/938d68ed832c 一.前言 前段时间看了几个开源项目,发现他们保持线程同步的方式各不相同,有@synchronized. ...

  10. ubuntu中安装jdk 分类: java 学习笔记 linux ubuntu 2015-07-06 17:49 74人阅读 评论(0) 收藏

    参考文献:ubuntu 13.04 安装 JDK 先去oracle官网下载jdk,这一段我就不赘述了. 下载好之后先解压,解压方式参见 linux常用的压缩与解压缩命令 ,解压之后,将文件剪贴至/us ...