将png图像数据格式转换成jpg数据格式,如何转换?

将png图像数据格式转换成jpg数据格式,如何转换? 希望能有注释的源代码,还希望解释一下原理,并有个demo。 使用linpng库和zlib库以及libjpeg库。用C++/C写,平台是VS2010

 #pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <conio.h>
#include <windows.h>
#include <atlimage.h>
#include <objidl.h>
void DrawPic(HDC hdc,char *buf,int len) {
    HGLOBAL hMem=GlobalAlloc(GMEM_FIXED,len);
    BYTE* pMem=(BYTE*)GlobalLock(hMem);
    memcpy(pMem,buf,len);
    IStream* pStream;
    HRESULT hr=CreateStreamOnHGlobal(pMem,FALSE,&pStream);

    CImage img;
    img.Load(pStream);
    img.Draw(hdc,CPoint(0,0));

    img.Destroy();
    pStream->Release();
    GlobalUnlock(hMem);
    GlobalFree(hMem);
}
//HWND WINAPI GetConsoleWindow();
void HideTheCursor() {
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    if (GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = FALSE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
void ShowTheCursor() {
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    if (GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = TRUE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
int main() {
    HWND  hwnd;
    HDC   hdc;
    HFONT hfont;
    HBITMAP hbm;
    HDC hdcBits;
    BITMAP bm;

    system("color F0");
    system("cls");
    HideTheCursor();
    hwnd  = GetConsoleWindow();
    hdc   = GetDC(hwnd);
    hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "华文楷体");
    SelectObject(hdc,hfont);
    TextOut(hdc,10,10,"这是泡泡",8);
    DeleteObject(hfont);
    hbm=(HBITMAP)LoadImage(0,"C:\\Windows\\Soap Bubbles.bmp",IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);
    if (hbm) {
        hdcBits = CreateCompatibleDC(hdc);
        GetObject (hbm, sizeof(BITMAP), &bm);
        SelectObject(hdcBits,hbm);
        BitBlt(hdc,200,10,bm.bmWidth, bm.bmHeight,hdcBits,0,0,SRCCOPY);
        DeleteDC(hdcBits);
        DeleteObject(hbm);
    }
    getch();
    FILE *f;
    f=fopen("c:\\new\\tmp.jpg","rb");
    if (f) {
        int fl=filelength(fileno(f));
        char *buf=(char *)malloc(fl);
        if (buf) {
            fread(buf,fl,1,f);
        }
        fclose(f);
        if (buf) {
            DrawPic(hdc,buf,fl);
            free(buf);
        }
    }
    ReleaseDC(hwnd,hdc);
    getch();
    system("color 07");
    system("cls");
    ShowTheCursor();
    return 0;
}

png有透明通道的,jpg没有透明通道,png转换成jpg,那你透明的部分,写成黑色或者白色么。