//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 = {, , , };
::SetBkMode(hdcMem, TRANSPARENT);
::DrawText(hdcMem, "Hello World.", -, &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,,);
img3.MixFrom(img2,w1,); img3.Save("f:\\3.jpg",CXIMAGE_FORMAT_JPG);
}
//图片裁剪
CxImage image;
bool bRet = image.Load("1.jpg");
CxImage smallImg;
bRet = image.Crop(,,,, &smallImg); uint8_t* buffer = ;
int32_t size = ;
smallImg.Encode(buffer, size, CXIMAGE_FORMAT_JPG);
std::string sData = std::string((char*)buffer, size);
smallImg.FreeMemory(buffer); bRet = smallImg.Save("2.jpg",CXIMAGE_SUPPORT_JPG);
图像旋转
image.Rotate(angle);
image.RotateLeft();
image.RotateRight();