jpg转bmp c语言 linux,C语言实现BMP转换JPG的方法
/****************************************************************************
名称: jpeg.c
功能: linux下bmp转化为jpeg程序源代码
日期: 2010.01.26
注意: 编译时加“-ljpeg”(gcc -o bmp2jpg jpeg.c -ljpeg)
*****************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define JPEG_QUALITY 95 //图片质量
int Bmp2Jpg(const char *bmp_file, const char *jeg_file, const int width, const int height)
{
FILE *fd;
int ret;
unsigned char *data;
long sizeImage;
int depth = 3;
JSAMPROW * row_pointer;
long rgb_index = 0;
int i=0;
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE *outfile;
;
// Read bmp image data
sizeImage = width*height*3;
data = (unsigned char*)malloc(sizeImage);
fd = fopen(bmp_file, "rb");
if(!fd)
{
printf("ERROR1: Can not open the image.\n");
free(data);
return -1;
}
fseek(fd, 54, SEEK_SET);
ret = fread(data, sizeof(unsigned char)*sizeImage, 1, fd);
if(ret == 0)
{
if(ferror(fd))
{
printf("\nERROR2: Can not read the pixel data.\n");
free(data);
fclose(fd);
return -1;
}
}
//Convert BMP to JPG
cinfo.err = jpeg_std_error(&jerr);
//* Now we can initialize the JPEG compression object.
jpeg_create_compress(&cinfo);
if ((outfile = fopen(jeg_file, "wb")) == NULL)
{
fprintf(stderr, "can't open %s\n", jeg_file);
return -1;
}
jpeg_stdio_dest(&cinfo, outfile);
cinfo.image_width = width;
//* image width and height, in pixels
cinfo.image_height = height;
cinfo.input_components = depth;
//* # of color components per pixel
cinfo.in_color_space = JCS_RGB;
//* colorspace of input image
jpeg_set_defaults(&cinfo);
//Now you can set any non-default parameters you wish to.
//Here we just illustrate the use of quality (quantization table) scaling:
jpeg_set_quality(&cinfo, JPEG_QUALITY, TRUE );
//* limit to baseline-JPEG values
jpeg_start_compress(&cinfo, TRUE);
//一次写入
int j=0;
row_pointer = malloc(height*width*3);
char * line[300];
for(i=0;i
{
unsigned char * lineData = NULL;
lineData = malloc(width*3);
line[i]=lineData;
for(j=0;j
{
lineData[j*3+2] = data[rgb_index];
rgb_index ++;
lineData[j*3+1] = data[rgb_index];
rgb_index ++;
lineData[j*3+0] = data[rgb_index];
rgb_index ++;
}
row_pointer[height-i-1] = lineData;
}
jpeg_write_scanlines(&cinfo, row_pointer, height);
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
for (i=0; i
{
free(line[i]);
}
free(row_pointer);
free(data);
fclose(fd);
fclose(outfile);
return 0;
}
jpg转bmp c语言 linux,C语言实现BMP转换JPG的方法相关推荐
- odbc c语言 linux,C语言ODBC数据库操作
今天我们来介绍一下C语言操作数据库的方法,这里我们使用的是ODBC方式.环境是WIN7+VC6.其他环境也差不多,具体情况具体分析. 首先是环境的配置以及数据源的添加.这里就不去解释了,相关资料网上有 ...
- 在 Ubuntu 上通过命令行改变 Linux 系统语言
这是一个快速教程,展示了在 Ubuntu 和其他 Linux 发行版上从命令行改变语言的步骤. 事实上,我一直在写西班牙语的文章.如果你没有访问过它并且/或你是一个讲西班牙语的人,请访问 It's F ...
- r语言工作路径linux,R语言实用基础知识_工作路径-注释-安装和卸载R包_2019-12-01...
R语言的实用基础知识有很多,都是我在工作和学习中所整理的,有的是看书整理的,也有的是从网络上的各种博客.各种资源获取的,所以我采用日更的方式进行支持整理和更新,希望能够帮到屏幕前的你! 今天是我日更的 ...
- c语言linux打印运行时间(耗时) gettimeofday()、timeval、<sys/time.h>
#include <stdio.h> #include <sys/time.h>double __get_us(struct timeval t) { return (t.tv ...
- 用C语言Linux下打印带颜色的字符串
用C语言Linux下打印带颜色的字符串 字背景颜色范围:40----49 40:黑 41:深红 42:绿 43:黄色 44:蓝色 45:紫色 46:深绿 47:白色 字颜色:30---------- ...
- Linux C语言调用C++动态链接库
Linux C语言调用C++动态链接库 标签: C调用C++库 2014-03-10 22:56 3744人阅读 评论(0) 收藏 举报 分类: [Linux应用开发](48) 版权声明:本文为博主原 ...
- Linux C语言结构体
前面学习了c语言的基本语法特性,本节进行更深入的学习. 预处理程序. 编译指令: 预处理, 宏定义, 建立自己的数据类型:结构体,联合体,动态数据结构 c语言表达式工具 逻辑运算符: & | ...
- c语言linux TCP长连接 socket收发范例 断开自动重连
原文链接:https://blog.csdn.net/chenhao0568/article/details/103420615 c语言linux TCP长连接 socket收发范例 断开自动重连 改 ...
- linux更改语言脚本,Linux shell脚本入门——shell语言脚本【CentOS】
认识脚本 是使用一种特定的描述性语言,依据一定的格式编写的可执行文件.脚本语言又被称为扩建的语言, 或者动态语言, 是一种编程语言, 用来控制软件应用程序, 脚本通常是以文本 (ASCⅡ) 保存, 只 ...
- linux C语言多线程库pthread中条件变量的正确用法逐步详解
linux C语言多线程库pthread中条件变量的正确用法: 了解pthread常用多线程API和pthread互斥锁,但是对条件变量完全不知道或者不完全了解的人群. 关于条件变量的典型应用,可以参 ...
最新文章
- 无责任畅想:云原生中间件的下一站
- java集群解析文件_干货:一文详解Redis集群原理核心内容
- Windows 10如何消除文件夹右上角的“相对箭头”?
- Dynamic动态类型
- (4)vue.js 基础语法
- 电源管理方案APM和ACPI比较
- HDU 6437 (费用流)
- 定义一个数组,里面存放星期一、星期二…… 直到星期日的英语写法,分别按倒序和排序后的顺序显示 数组所有元素。
- 社保已经交够15年了,还需要再交吗?到退休年龄时可以退休吗?
- iOS6的控制屏幕旋转技巧
- RSA/ECDSA host key has changed 错误
- 杰里之104X之输出 3 路 PMW【篇】
- [NodeJS实战][Vue实战]Vue-PixiJS [开箱可用][新手极简]
- 鸿蒙tv文件管理,手机如何推送文件到电视,三款TV投屏软件亲测推荐!
- 伺服的基础知识及简单应用
- Python量化学习笔记02——量化投资——以Python为工具 Part01-C02
- 面试的时候怎样回答技术面试题?
- 计算机网络技术用什么笔记本好,适合设计专业的笔记本电脑推荐榜单-好用的设计类笔记本电脑推荐...
- QGIS基本功 | 22 QGIS工程文件属性设置(3)——宏、QGIS服务
- slqmap的爆库爆表爆字段(以本地搭建的DVWA为例)
热门文章
- 测试和开发之间的博弈--没有硝烟的战争
- 现阶段有哪些方式可以快速感知元宇宙?
- 嬴彻科技日: 发布《自动驾驶卡车量产白皮书》分享从量产走向无人技术路线
- 利用电脑玩android版天天连萌刷高分 二,利用电脑玩Android版“天天连萌”刷高分(二)——图像识别...
- Ubuntu下面scroll lock无法使用的解决方法
- 洛谷P2306 被yyh虐的mzc
- android 异常 android Removing unused resources requires unused code shrinking to be turned on.
- 计算机病毒的历史:1986-1993(译文…
- 用R语言看武汉市武昌区房租出租情况
- arcgis人口空间化_基于遥感和GIS的人口数据空间化研究进展及案例分析