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);

    ;
} 

最新文章

  1. php内核分析(二)-ZTS和zend_try
  2. Salesforce学习笔记(一)
  3. SQL Server 2008中的数据压缩
  4. 数据转移发现font有问题
  5. maven中GroupID 和ArtifactID怎么写
  6. C#图片压缩的实现方法
  7. 在javascript中检查一个值是否为integer
  8. Unity NGUI弧形血条的制作
  9. 即时Web通信总结
  10. FragmentTransactionExtended
  11. asp.net生成二维码的方法
  12. [置顶] JQuery插件学习教程
  13. 『重构--改善既有代码的设计』读书笔记----Extract Method
  14. 使用WSE实现Web Service安全----我的第一篇
  15. 使用pentaho工具将数据库数据导入导出为Excel
  16. javaWeb学习总结(1)- JavaWeb开发入门
  17. 根据文件大小自动判断单位B,KB,MB,GB
  18. 2018 icpc-ecfinal后记
  19. 【23】备忘录模式(Memento Pattern)
  20. Vim命令图解及快捷键讲解

热门文章

  1. INSPIRED启示录 读书笔记 - 第27章 合理运用瀑布式开发方法
  2. lockingModel in log4net 日志文件不能被其他进程写入
  3. shell删除最后一列、删除第一行、比较文件
  4. mongodb 的安装(Centor OS )
  5. EntityFramework 学习 一 Multiple Diagrams in Entity Framework 5.0
  6. 泛型学习第二天——C#中的List&lt;string&gt;泛型类示例
  7. HDU 5884 Sort(2016年青岛网络赛 G 二分+贪心+小优化)
  8. WinDBG__独立安装文件
  9. spring boot: 组合注解与元注解
  10. 分享知识-快乐自己:Spring_IOC(控制反转)详解