FreeImage库如何转换图片格式?
FreeImage下载地址:http://freeimage.sourceforge.net/
#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
#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库如何转换图片格式?的更多相关文章
- java批量转换图片格式
废话不多直接上代码,代码其实也不多.... package com.qiao.testImage; import java.awt.image.BufferedImage; import java.i ...
- 使用IMAGEMAGICK的CONVERT工具批量转换图片格式
使用IMAGEMAGICK的CONVERT工具批量转换图片格式 http://www.qiansw.com/linux-imagemagick-convert-img.html Home > 文 ...
- Mac电脑如何转换图片格式?ImageWell for Mac转换图片格式教程
想用Mac电脑转换图片格式?我想你可以借助ImageWell for Mac软件!ImageWell是一款简单好用的的图像处理工具,具有显示,编辑,处理,保存等功能.下面小编来为大家演示在Mac电脑上 ...
- 【最简单】不用ps也可以批量转换图片格式
不废话直接开始~ 1.新建文件夹,把需要转换的图片放进去,如图: 2.文件夹里建一txt文本,重点来了!txt文本的内容,如果是jpg转为png,则输入“ren *.jpg *.png”,同理png转 ...
- ubuntu 转换图片格式的方法(sam2p, imagemagick)
(1) 终端:sudo apt-get install sam2p sam2p [原图片名.格式] [目标图片名.格式] 即可在同一目录下生成目标图片格式 (2) 终端: sudo apt-get i ...
- python转换图片格式
在图片所在的路径下,打开命令窗口 bmeps -c picturename.png picturename.eps
- 使用WIC组件转换图片格式
#include <windows.h>#include <Wincodec.h>#pragma comment(lib, "Windowscodecs.lib&qu ...
- 利用C#转换图片格式及转换为ico
注意:转换为ICO后效果不好. 源代码: using System;using System.Collections.Generic;using System.Text;using System.Dr ...
- ImageMagick 转换图片格式
[root@ drawable-hdpi-v4]# convert ic_launcher.jpeg ic_launcher.png [root@ drawable-hdpi-v4]# file ic ...
随机推荐
- linux_思想
linux有哪些重要的思想? 1. 做的越多错的越多 2. 纸包不住火 3. 操作重要文件前备份,操作后查看结果 4. 看到命令输出结果,可能命令有个选择直接获得对应值 5. 先定行,再定列
- 剑指offfer:二维数组中的查找
题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成这样一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 例如: 1 2 ...
- Linux指令--rm, rmdir
rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所有文件及子目录均删除.对于链接文件,只是删除了链接,原有文件均保持不变.rm是一个危险的命令,使用的时 ...
- linkin大话数据结构--字符串,数组,list之间的互转
在实际开发中,我们经常会用到字符串,字符数组,字符list,当然也会不可避免的进行这3者之间的互相转换. 在使用到Apache和Google下的common包,可以这样子实现: package tz. ...
- springcloud(十二):使用Spring Cloud Sleuth和Zipkin进行分布式链路跟踪
随着业务发展,系统拆分导致系统调用链路愈发复杂一个前端请求可能最终需要调用很多次后端服务才能完成,当整个请求变慢或不可用时,我们是无法得知该请求是由某个或某些后端服务引起的,这时就需要解决如何快读定位 ...
- mybatis 中文文档
http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html
- eclipse每次闪退后都提示查看\workspace\.metadata\.log
错误如下: 找到<workspace>/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi"文件,将其删掉,再重启 ...
- JDK及Tomcat集成到MyEclipse
JDK及Tomcat集成到MyEclipse 1.安装好MyEclipse 2.破解 3.配置环境JDK D:\jdk1.6.0_21\bin; ==>放在系统path前面 4.打开MyEcli ...
- vs调试dll工程
dll本身是没法运行的,必须在其它工程调用dll时候才会运行. 所以,调试dll首先要将调用dll的工程和dll工程联系起来. 解决方案中添加dll工程: 现在dll 和 应用程序两个工程就都在一个解 ...
- 使用open-falcon监控Nginx
一.介绍 前段时间部署试用了open-falcon v0.2,官方文档很详细,难度也不是很大.监控Nginx也参考了文档推荐的方式,文档地址:http://book.open-falcon.org/z ...