这里有一个例子,不过得有库:Victor Image Processing Library
BMP to JPEG - the C Source Code
Requires Victor Image Processing Library v 4.25 or higher.
int bmp2jpeg(char far *src_fname, char far *des_fname)
{
imgdes tmpimage;
int rcode, quality=75, vbitcount;
BITMAPINFOHEADER bdat; // Reserve space for BMP struct
// Get info on the file we're to load
rcode = bmpinfo(src_fname, &bdat);
if(rcode != NO_ERROR) {
return(rcode);
}
vbitcount = bdat.biBitCount;
if(vbitcount >= 16) // 16-, 24-, or 32-bit image is loaded into 24-bit buffer
vbitcount = 24;
// Allocate space for an image
rcode = allocimage(&tmpimage, (int)bdat.biWidth, (int)bdat.biHeight, vbitcount);
if(rcode != NO_ERROR) {
return(rcode);
}
if(vbitcount == 1) { // If we loaded a 1-bit image, convert to 8-bit grayscale
// because jpeg only supports 8-bit grayscale or 24-bit color images
imgdes tmp2image;