FreeImage下载地址:http://freeimage.sourceforge.net/

//freeimagemain.h

#ifndef FREEIMAGEMAIN_H
#define FREEIMAGEMAIN_H #include <QWidget>
#include <QtCore>
#include <QStatusBar>
#include <QFileDialog>
#include "FreeImage.h"
namespace Ui {
class FreeImageMain;
} class FreeImageMain : public QWidget
{
Q_OBJECT public:
explicit FreeImageMain(QWidget *parent = 0);
~FreeImageMain();
bool ImageTransformationImage(QString sourcePath,QString destinationPath) const;
//根据文件路径获取格式
int GetImagePathSuffix(QString path) const;
private:
Ui::FreeImageMain *ui;
QTextCodec *textCodec;
QString m_sourcePath;
QString m_destinationPath;
QStatusBar *statusBar;
}; #endif // FREEIMAGEMAIN_H

//freeimagemain.cpp

#include "freeimagemain.h"
#include "ui_freeimagemain.h"
#include <stdio.h>
#include <stdlib.h>
FreeImageMain::FreeImageMain(QWidget *parent) :
QWidget(parent),
ui(new Ui::FreeImageMain)
{
ui->setupUi(this);
textCodec = QTextCodec::codecForName("GBK");
statusBar = new QStatusBar;
ui->verticalLayout->addWidget(statusBar);
QObject::connect(ui->pushButton_load,&QPushButton::pressed,[=](){
this->m_sourcePath = QFileDialog::getOpenFileName(this,tr(textCodec->toUnicode("加载位图").toStdString().data()), "./", tr("Image Files (*ico *.png *.jpg *.bmp)"));
if(this->m_sourcePath.isEmpty())
{
statusBar->showMessage(textCodec->toUnicode("位图加载路径不能为空!"),3000);
}
else
{
statusBar->showMessage(textCodec->toUnicode("位图加载路径获取成功!"),3000);
}
});
QObject::connect(ui->pushButton_save,&QPushButton::pressed,[=](){
//源路径为空直接返回
if(this->m_sourcePath.isEmpty())
{
statusBar->showMessage(textCodec->toUnicode("请先加载位图路径!"),3000);
return;
}
this->m_destinationPath = QFileDialog::getSaveFileName(this,tr(textCodec->toUnicode("加载位图").toStdString().data()), "./", tr("Image Files (*ico *.png *.jpg *.bmp)"));
if(this->m_destinationPath.isEmpty())
{
statusBar->showMessage(textCodec->toUnicode("存储位图路径不能为空!"),3000);
return;
}
else
{
statusBar->showMessage(textCodec->toUnicode("位图存储路径获取成功!"),3000);
this->ImageTransformationImage(m_sourcePath,m_destinationPath);
}
});
} FreeImageMain::~FreeImageMain()
{
statusBar->deleteLater();
delete ui;
} int FreeImageMain::GetImagePathSuffix(QString path) const
{
// QString::compare(path.split(".").constLast(), "BMP", Qt::CaseInsensitive);
QString Suffix = path.split(".").constLast().toUpper();
if(Suffix == "BMP")
{
return FIF_BMP;
}
else if (Suffix == "ICO")
{
return FIF_ICO;
}
else if (Suffix == "JPEG")
{
return FIF_JPEG;
}
else if (Suffix == "JNG")
{
return FIF_JNG;
}
else if (Suffix == "KOALA")
{
return FIF_KOALA;
}
else if (Suffix == "LBM")
{
return FIF_LBM;
}
else if (Suffix == "IFF")
{
return FIF_IFF;
}
else if (Suffix == "MNG")
{
return FIF_MNG;
}
else if (Suffix == "PBM")
{
return FIF_PBM;
}
else if (Suffix == "PBMRAW")
{
return FIF_PBMRAW;
}
else if (Suffix == "PCD")
{
return FIF_PCD;
}
else if (Suffix == "PCX")
{
return FIF_PCX;
}
else if (Suffix == "PGM")
{
return FIF_PGM;
}
else if (Suffix == "PGMRAW")
{
return FIF_PGMRAW;
}
else if (Suffix == "PNG")
{
return FIF_PNG;
}
else if (Suffix == "PPM")
{
return FIF_LBM;
}
else if (Suffix == "PPMRAW")
{
return FIF_PPMRAW;
}
else if (Suffix == "RAS")
{
return FIF_RAS;
}
else if (Suffix == "TARGA")
{
return FIF_TARGA;
}
else if (Suffix == "TIFF")
{
return FIF_TIFF;
}
else if (Suffix == "WBMP")
{
return FIF_WBMP;
}
else if (Suffix == "PSD")
{
return FIF_PSD;
}
else if (Suffix == "CUT")
{
return FIF_CUT;
}
else if (Suffix == "XBM")
{
return FIF_XBM;
}
else if (Suffix == "XPM")
{
return FIF_XPM;
}
else if (Suffix == "DDS")
{
return FIF_DDS;
}
else if (Suffix == "GIF")
{
return FIF_GIF;
}
else if (Suffix == "HDR")
{
return FIF_HDR;
}
else if (Suffix == "FAXG3")
{
return FIF_FAXG3;
}
else if (Suffix == "SGI")
{
return FIF_SGI;
}
else if (Suffix == "EXR")
{
return FIF_EXR;
}
else if (Suffix == "J2K")
{
return FIF_J2K;
}
else if (Suffix == "JP2")
{
return FIF_JP2;
}
else if (Suffix == "PFM")
{
return FIF_PFM;
}
else if (Suffix == "PICT")
{
return FIF_PICT;
}
else if (Suffix == "RAW")
{
return FIF_RAW;
}
else if (Suffix == "WEBP")
{
return FIF_WEBP;
}
else if (Suffix == "JXR")
{
return FIF_JXR;
}
return FIF_UNKNOWN; } bool FreeImageMain::ImageTransformationImage(QString sourcePath, QString destinationPath) const
{
int imageFormat = FreeImage_GetFIFFromFilename(sourcePath.toStdString().data());//获取文件格式
//static_cast<FREE_IMAGE_FORMAT>(imageFormat) 把 int 转换成 FREE_IMAGE_FORMAT 枚举类型
FIBITMAP *dib = FreeImage_Load(static_cast<FREE_IMAGE_FORMAT>(imageFormat),sourcePath.toStdString().data());
if(dib == NULL)
{
// qDebug()<<textCodec->toUnicode("图像加载失败!");
statusBar->showMessage(textCodec->toUnicode("图像加载失败!"),3000);
return false;
}
// qDebug()<<textCodec->toUnicode("ImageType:")<<FreeImage_GetImageType(dib);//获取位图类型
// qDebug()<<textCodec->toUnicode("BPP:")<<FreeImage_GetBPP(dib);//获取位深
unsigned int width = FreeImage_GetWidth(dib);//获取图像的宽
unsigned int height = FreeImage_GetHeight(dib);//获取图像的高
if(imageFormat == FIF_ICO && width!=height)
{
// qDebug()<<textCodec->toUnicode("ICO-请确保位图的宽和高相等!");
statusBar->showMessage(textCodec->toUnicode("ICO-请确保位图的宽和高相等!"),3000);
}
if(FreeImage_Save(static_cast<FREE_IMAGE_FORMAT>(GetImagePathSuffix(destinationPath)),dib,destinationPath.toStdString().data()))
{
qDebug()<<textCodec->toUnicode("位图格式转换成功");
statusBar->showMessage(textCodec->toUnicode("位图格式转换成功"),3000);
return true;
}
else
{
qDebug()<<textCodec->toUnicode("位图格式转换失败");
statusBar->showMessage(textCodec->toUnicode("位图格式转换失败"),3000);
return false;
}
} //RC_ICONS = ./LOGO.ico

FreeImage库如何转换图片格式?的更多相关文章

  1. java批量转换图片格式

    废话不多直接上代码,代码其实也不多.... package com.qiao.testImage; import java.awt.image.BufferedImage; import java.i ...

  2. 使用IMAGEMAGICK的CONVERT工具批量转换图片格式

    使用IMAGEMAGICK的CONVERT工具批量转换图片格式 http://www.qiansw.com/linux-imagemagick-convert-img.html Home > 文 ...

  3. Mac电脑如何转换图片格式?ImageWell for Mac转换图片格式教程

    想用Mac电脑转换图片格式?我想你可以借助ImageWell for Mac软件!ImageWell是一款简单好用的的图像处理工具,具有显示,编辑,处理,保存等功能.下面小编来为大家演示在Mac电脑上 ...

  4. 【最简单】不用ps也可以批量转换图片格式

    不废话直接开始~ 1.新建文件夹,把需要转换的图片放进去,如图: 2.文件夹里建一txt文本,重点来了!txt文本的内容,如果是jpg转为png,则输入“ren *.jpg *.png”,同理png转 ...

  5. ubuntu 转换图片格式的方法(sam2p, imagemagick)

    (1) 终端:sudo apt-get install sam2p sam2p [原图片名.格式] [目标图片名.格式] 即可在同一目录下生成目标图片格式 (2) 终端: sudo apt-get i ...

  6. python转换图片格式

    在图片所在的路径下,打开命令窗口 bmeps -c picturename.png picturename.eps

  7. 使用WIC组件转换图片格式

    #include <windows.h>#include <Wincodec.h>#pragma comment(lib, "Windowscodecs.lib&qu ...

  8. 利用C#转换图片格式及转换为ico

    注意:转换为ICO后效果不好. 源代码: using System;using System.Collections.Generic;using System.Text;using System.Dr ...

  9. ImageMagick 转换图片格式

    [root@ drawable-hdpi-v4]# convert ic_launcher.jpeg ic_launcher.png [root@ drawable-hdpi-v4]# file ic ...

随机推荐

  1. python_如何对实例属性进行类型检查?

    案例: 在某项目中,我们实现了一些类,并希望能像静态语言那样对他们的实例属性进行类型检查 p = Person() p.name = 'xi_xi'         # 必须是str p.age = ...

  2. ActiveMQ入门练习

    ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台已经是很久 ...

  3. [Java 教程 01] Hello,Java!

    前言 从事编程已经有一段时间了,突然发现,Java作为我的第一编程语言,自己似乎对她并有一个系统的思想.当下Java依旧保持着超高的热度,新特性也不断出现,从当初学习的java6版本到最近刚出的jav ...

  4. 小白的Python之路 day5 re正则模块

    re正则模块 一.概述 就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,要讲他的具体用法要讲一本书!它内嵌在Python中,并通过 re 模块实现.你可以为想要匹配的相应字符串 ...

  5. Win和Linux查看端口和杀死进程

    title: Win和Linux查看端口和杀死进程 date: 2017-7-30 tags: null categories: Linux --- 本文介绍Windows和Linux下查看端口和杀死 ...

  6. 【Spring】HttpMessageConverter的作用及替换

    相信使用过Spring的开发人员都用过@RequestBody.@ResponseBody注解,可以直接将输入解析成Json.将输出解析成Json,但HTTP 请求和响应是基于文本的,意味着浏览器和服 ...

  7. jQuery中的DOM操作------复制及包裹节点

    1.复制节点: 如果单击<li>元素后需要再复制一个<li>元素,可以用clone()方法来完成: $(this).clone().appendTo("ul" ...

  8. Cypher查询语言--Neo4j 入门 (一)

    目录 操作符 参数 标识符 注解 Start 通过id绑定点 通过id绑定关系 通过id绑定多个节点 所有节点 通过索引查询获取节点 通过索引查询获取关系 多个开始点  Cypher是一个描述性的图形 ...

  9. 手工搭建基于ABP的框架 - 工作单元以及事务管理

    一个业务功能往往不只由一次数据库请求(或者服务调用)实现.为了功能的完整性,我们希望如果该功能执行一半时出错,则撤销前面已执行的改动.在数据库层面上,事务管理实现了这种完整性需求.在ABP中,一个完整 ...

  10. selenium打开chrome浏览器代码

    import os from selenium import webdriver chromedriver = "C:\Program Files (x86)\Google\Chrome\A ...