首页 > 代码库 > CxImage整理(叠加字符/图像合并)

CxImage整理(叠加字符/图像合并)

//CxImage叠加字符void CCxImageTestDlg::OnBnClickedButton1(){    CxImage imgJPG;   // 定义一个CxImage对象    imgJPG.Load("1.jpg", CXIMAGE_FORMAT_JPG);   //先装载jpg文件        // 判断加载的jpg文件是否存在。    if (imgJPG.IsValid())    {        //得到文件对应的HBITMAP        HBITMAP hbmp = imgJPG.MakeBitmap();        HWND hwnd = GetSafeHwnd();        HDC hdc = ::GetDC(hwnd);        HDC hdcMem = ::CreateCompatibleDC(hdc);        SelectObject(hdcMem, hbmp);        RECT rc = {50, 50, 200, 200};        ::SetBkMode(hdcMem, TRANSPARENT);        ::DrawText(hdcMem, "Hello World.", -1, &rc,  DT_VCENTER);        CxImage imgBmp;        imgBmp.CreateFromHBITMAP(hbmp);        imgBmp.Save("1jpg.jpg", CXIMAGE_FORMAT_JPG);        ::ReleaseDC(hwnd, hdc);                ::DeleteDC(hdcMem);        ::DeleteDC(hdc);    }}//左右合并两张图片,合并后的图片与原图等高;上下合并可类推。//如果只是在图1上嵌入图2,处理后的图还是和图1的高宽一样。则只需要用MixFrom函数void mergerImage(void){    CxImage img1,img2,img3;    int h1,w1,h2,w2,h3,w3,bpp;    img1.Load("F:\\1.jpg");    img2.Load("F:\\2.jpg");    h1=img1.GetHeight();    w1=img1.GetWidth();    h2=img2.GetHeight();    w2=img2.GetWidth();    h3=h1;    w3=w1+w2;    bpp=img1.GetBpp();    img3.Create(w3,h3,bpp);    img3.MixFrom(img1,0,0);    img3.MixFrom(img2,w1,0);    img3.Save("f:\\3.jpg",CXIMAGE_FORMAT_JPG);}

 

CxImage整理(叠加字符/图像合并)