BMP格式转JPEG格式
2024-10-19 11:54:21
int Bmp2Jpg(const char *bmp_data, const char *jeg_file, const int width, const int height) { int ret; ; JSAMPROW * row_pointer; ; ; struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; FILE *outfile; //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); ; } 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); //一次写入 ; row_pointer = ); ]; ;i<height;i++) { unsigned char * lineData = NULL; lineData = ); line[i]=lineData; ;j<width;j++) { lineData[j*+] = bmp_data[rgb_index]; rgb_index ++; lineData[j*+] = bmp_data[rgb_index]; rgb_index ++; lineData[j*+] = bmp_data[rgb_index]; rgb_index ++; } row_pointer[height-i-] = lineData; } jpeg_write_scanlines(&cinfo, row_pointer, height); jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); ; i<height; i++) { free(line[i]); } free(row_pointer); fclose(outfile); ; }
最新文章
- php内核分析(二)-ZTS和zend_try
- Salesforce学习笔记(一)
- SQL Server 2008中的数据压缩
- 数据转移发现font有问题
- maven中GroupID 和ArtifactID怎么写
- C#图片压缩的实现方法
- 在javascript中检查一个值是否为integer
- Unity NGUI弧形血条的制作
- 即时Web通信总结
- FragmentTransactionExtended
- asp.net生成二维码的方法
- [置顶] JQuery插件学习教程
- 『重构--改善既有代码的设计』读书笔记----Extract Method
- 使用WSE实现Web Service安全----我的第一篇
- 使用pentaho工具将数据库数据导入导出为Excel
- javaWeb学习总结(1)- JavaWeb开发入门
- 根据文件大小自动判断单位B,KB,MB,GB
- 2018 icpc-ecfinal后记
- 【23】备忘录模式(Memento Pattern)
- Vim命令图解及快捷键讲解
热门文章
- INSPIRED启示录 读书笔记 - 第27章 合理运用瀑布式开发方法
- lockingModel in log4net 日志文件不能被其他进程写入
- shell删除最后一列、删除第一行、比较文件
- mongodb 的安装(Centor OS )
- EntityFramework 学习 一 Multiple Diagrams in Entity Framework 5.0
- 泛型学习第二天——C#中的List<;string>;泛型类示例
- HDU 5884 Sort(2016年青岛网络赛 G 二分+贪心+小优化)
- WinDBG__独立安装文件
- spring boot: 组合注解与元注解
- 分享知识-快乐自己:Spring_IOC(控制反转)详解