将图片1920 * 1080图片缩放成 320*180并且填充 320*70 320*70 变成320*320 jpeg

放 rgba转化成jpeg的 部分 其他部分利用了T31开发库 很麻烦

//rgba -> rgb 
int clipRgbaToJpgFile(const char *pFileName, const char* pRgbaData, const int nWidth, const int nHeight, const int nClipLeft, const int nClipTop, const int nClipWidth, const int nClipHeight)
{
    char* pClipSource     = NULL;
    char* pClipData       = NULL;
    int pixcelBytes       = nClipWidth*nClipHeight*3;
    int i = 0;
    int j = 0;
 	
    pClipSource = malloc(pixcelBytes);
    if (!pClipSource)
    {
        return -1;
    }
    //移动到制定位置
    pRgbaData += nClipTop * nWidth * 4;
    pRgbaData += nClipLeft * 4;
 
    pClipData = pClipSource;
    for (i=0; i<nClipHeight; i++)
    {
        for (j=0; j<nClipWidth; j++)
        {
            //这样性能如何?
            memcpy(pClipData, pRgbaData, 3);
            pRgbaData += 4;
            pClipData += 3;
        }
        pRgbaData += (nWidth-nClipWidth)    * 4;
    }
    rgb2jpg(pFileName, pClipSource, nClipWidth, nClipHeight);
    //释放资源
    free(pClipSource);
 
    return 0;
}


int rgb2jpg(const char *jpg_file,const char *pdata, int width, int height)
{
    int depth = 3;
    JSAMPROW row_pointer[1];
    struct jpeg_compress_struct cinfo;
    struct jpeg_error_mgr jerr;
    FILE *outfile;
 
    if ((outfile = fopen(jpg_file, "wb")) == NULL)
    {
        return -1;
    }
 
    cinfo.err = jpeg_std_error(&jerr);
    jpeg_create_compress(&cinfo); 
    jpeg_stdio_dest(&cinfo, outfile);
 
    cinfo.image_width      = width;
    cinfo.image_height     = height;
    cinfo.input_components = depth;
    cinfo.in_color_space   = JCS_RGB;
    jpeg_set_defaults(&cinfo);
 
    jpeg_set_quality(&cinfo, 90, TRUE );
    jpeg_start_compress(&cinfo, TRUE);
 
    int row_stride = width * depth;
    while (cinfo.next_scanline < cinfo.image_height)
    {
        row_pointer[0] = (JSAMPROW)(pdata + cinfo.next_scanline * row_stride);
        jpeg_write_scanlines(&cinfo, row_pointer, 1);
    }
 
    jpeg_finish_compress(&cinfo);
    jpeg_destroy_compress(&cinfo);
    fclose(outfile);
 
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值