Visual c++ 如何在VC++;

Visual c++ 如何在VC++;,visual-c++,Visual C++,如何在VC中将byte*转换成jpeg文件++ 我正在捕获视频样本并将其作为bmp文件写入,但我想使用ATL COM中的MFC支持将该视频样本写入jpeg文件。从它出现的情况来看,图像数据位于由字节对象指向的缓冲区中。请注意,该类型实际上是字节(全大写)。如果数据已经是JPEG格式,为什么不将数据写入一个文件(具有合适的“.jpg”或“.JPEG”扩展名)并尝试使用图像编辑器加载它?否则,您需要将其解码为原始格式并以JPEG格式编码 或者,您需要更详细地解释您的问题,最好使用一些代码。使用lib

如何在VC中将byte*转换成jpeg文件++


我正在捕获视频样本并将其作为bmp文件写入,但我想使用ATL COM中的MFC支持将该视频样本写入jpeg文件。

从它出现的情况来看,图像数据位于由
字节
对象指向的缓冲区中。请注意,该类型实际上是
字节
(全大写)。如果数据已经是JPEG格式,为什么不将数据写入一个文件(具有合适的“.jpg”或“.JPEG”扩展名)并尝试使用图像编辑器加载它?否则,您需要将其解码为原始格式并以JPEG格式编码


或者,您需要更详细地解释您的问题,最好使用一些代码。

使用libjpg。下载:

< P>原始图像数据到IGEMAGEK可以得到JPEG。

< P>你也可以尝试使用C++类来保存你的静态图片到JPEG编码文件。 例如,CodeProject上还有一些面向Windows API的替代方案

如果使用libjpeg支持编译,甚至可以使用库从Windows位图将JPEG渲染为文件。下面是我不久前为此开发的小扩展函数代码:

// libgd ext// libgd extension by Mateusz Loskot <mateusz at loskot dot net>
// Originally developed for Windows CE to enable direct drawing
// on Windows API Device Context using libgd API.
// Complete example available in libgd CVS:
// http://cvs.php.net/viewvc.cgi/gd/libgd/examples/windows.c?diff_format=u&revision=1.1&view=markup
//
gdImagePtr gdImageTrueColorAttachBuffer(int* buffer, int sx, int sy, int stride)
{
    int i;
    int height;
    int* rowptr;
    gdImagePtr im;
    im = (gdImage *) malloc (sizeof (gdImage));
    if (!im) {
        return 0;
    }
    memset (im, 0, sizeof (gdImage));
#if 0
    if (overflow2(sizeof (int *), sy)) {
        return 0;
    }
#endif

    im->tpixels = (int **) malloc (sizeof (int *) * sy);
    if (!im->tpixels) {
        free(im);
        return 0;
    }

    im->polyInts = 0;
    im->polyAllocated = 0;
    im->brush = 0;
    im->tile = 0;
    im->style = 0;

    height = sy;
    rowptr = buffer;
    if (stride < 0) {
        int startoff = (height - 1) * stride;
        rowptr = buffer - startoff;
    }

    i = 0;
    while (height--) {
        im->tpixels[i] = rowptr;
        rowptr += stride;
        i++;
    }

    im->sx = sx;
    im->sy = sy;
    im->transparent = (-1);
    im->interlace = 0;
    im->trueColor = 1;
    im->saveAlphaFlag = 0;
    im->alphaBlendingFlag = 1;
    im->thick = 1;
    im->AA = 0;
    im->cx1 = 0;
    im->cy1 = 0;
    im->cx2 = im->sx - 1;
    im->cy2 = im->sy - 1;
    return im;
}

void gdSaveJPEG(void* bits, int width, int height, const char* filename)
{
    bool success = false;
    int stride = ((width * 1 + 3) >> 2) << 2;
    gdImage* im = gdImageTrueColorAttachBuffer((int*)bits, width, height, -stride);
    if (0 != im)
    {
        FILE* jpegout = fopen(filename, "wb");
        gdImageJpeg(im, jpegout, -1);
        fclose(jpegout);
        success = true;
    }
    gdImageDestroy(im);
    return success;
}
//libgd ext//libgd extension by Mateusz Loskot
//最初为Windows CE开发,用于启用直接绘图
//在Windows API设备上下文上使用libgd API。
//libgd CVS中提供的完整示例:
// http://cvs.php.net/viewvc.cgi/gd/libgd/examples/windows.c?diff_format=u&revision=1.1&view=markup
//
gdImagePtr gdImageTrueColorAttachBuffer(int*buffer、int sx、int sy、int stride)
{
int i;
内部高度;
int*rowptr;
gd成像仪;
im=(gdImage*)malloc(sizeof(gdImage));
如果(!im){
返回0;
}
memset(im,0,sizeof(gdImage));
#如果0
if(溢出2(sizeof(int*),sy)){
返回0;
}
#恩迪夫
im->tpixels=(int**)malloc(sizeof(int*)*sy);
如果(!im->t像素){
免费(im);
返回0;
}
im->polyInts=0;
im->polyAllocated=0;
im->brush=0;
im->tile=0;
im->style=0;
高度=sy;
rowptr=缓冲区;
如果(步幅<0){
int STARTOF=(高度-1)*步幅;
rowptr=缓冲区-开始时间;
}
i=0;
而(高度--){
im->tpixels[i]=rowptr;
rowptr+=步幅;
i++;
}
im->sx=sx;
im->sy=sy;
im->透明=(-1);
im->interlace=0;
im->trueColor=1;
im->saveAlphaFlag=0;
im->alphaBlendingFlag=1;
im->thick=1;
im->AA=0;
im->cx1=0;
im->cy1=0;
im->cx2=im->sx-1;
im->cy2=im->sy-1;
返回即时消息;
}
void gdSaveJPEG(void*位、int-width、int-height、const-char*文件名)
{
布尔成功=假;

int stride=((宽度*1+3)>>2)字节*指向什么?RGB数据?您只是想使用JPEG压缩数据,还是想要一个有效的JPEG文件(包括可由其他应用程序读取的标题)?