目前就是按这种流程来走,一下是代码:
HRESULT hr;
if(m_pImagingFactory==NULL){
return;
}
IImage* pImage=NULL;
CDC *pPicDC=NULL;
CDC rotatedDC,memDC;
HBITMAP oldMemBitMap,oldRotateBitMap;
try{
CString pFileFullName=m_vfileList.at(m_iPicIndex);
hr=m_pImagingFactory->CreateImageFromFile(pFileFullName,&pImage);
if(FAILED(hr)){
goto finish;
}
RECT rectDraw;
GetClientRect(&rectDraw);
ImageInfo imageInfo;
pImage->GetImageInfo(&imageInfo);
RECT rectMem={0,0,imageInfo.Width,imageInfo.Height};
pPicDC =GetDC();
memDC.CreateCompatibleDC(pPicDC);
BITMAPINFO memBmi;
//memset(&memBmi, 0, sizeof(BITMAPINFO));
memBmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
memBmi.bmiHeader.biWidth = imageInfo.Width;
memBmi.bmiHeader.biHeight = imageInfo.Height;
memBmi.bmiHeader.biPlanes = 1;
memBmi.bmiHeader.biBitCount = 24;
memBmi.bmiHeader.biCompression = BI_RGB;
if ( m_hBitmapMem == NULL)
{
m_hBitmapMem =CreateDIBSection(memDC.GetSafeHdc(), &memBmi, DIB_RGB_COLORS, (void **)&m_lpMemData, NULL, 0);
}
oldMemBitMap = (HBITMAP)memDC.SelectObject(m_hBitmapMem);
pImage->Draw(memDC,&rectMem,NULL);
pImage->Release();
pImage=NULL;
RECT rectRotated;//旋转后rect
rotatedDC.CreateCompatibleDC(pPicDC);
Invalidate();
UpdateWindow();
BITMAPINFO rotatedBmi;
//memset(&rotatedBmi, 0, sizeof(BITMAPINFO));
rotatedBmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
rotatedBmi.bmiHeader.biWidth = imageInfo.Height;
rotatedBmi.bmiHeader.biHeight = imageInfo.Width;
rotatedBmi.bmiHeader.biPlanes = 1;
rotatedBmi.bmiHeader.biBitCount = 24;
rotatedBmi.bmiHeader.biCompression = BI_RGB;
//旋转
switch(m_iAngle){
case 90:{//90度旋转
rectRotated.left=0;
rectRotated.top=0;
rectRotated.right=imageInfo.Height;
rectRotated.bottom=imageInfo.Width;
m_hBitmapRotate = CreateDIBSection(rotatedDC.GetSafeHdc(), &rotatedBmi, DIB_RGB_COLORS, (void **)&m_lpDstData, NULL, 0);
//oldRotateBitMap=(HBITMAP)rotatedDC.SelectObject(m_hBitmapRotate);
int memStride = WIDTHBYTES(imageInfo.Width*memBmi.bmiHeader.biBitCount);
int rotateStride = WIDTHBYTES(imageInfo.Height*rotatedBmi.bmiHeader.biBitCount);
int index;
int index2;
for(int i=0;iStretchBlt(rectDraw.left,rectDraw.top,(rectDraw.right-rectDraw.left),(rectDraw.bottom-rectDraw.top),&rotatedDC,0,0,rectRotated.right,rectRotated.bottom,SRCCOPY);
}
catch(...){
printf("sdf");
goto finish;
}
finish:
memDC.SelectObject(oldMemBitMap);
rotatedDC.SelectObject(oldRotateBitMap);
DeleteObject(m_hBitmapMem);
m_hBitmapMem = NULL;
DeleteObject(m_hBitmapRotate);
rotatedDC.DeleteDC();
memDC.DeleteDC();
if(pPicDC!=NULL){
ReleaseDC(pPicDC);
}
if(pImage!=NULL){
pImage->Release();
pImage=NULL;
}
if(m_lpDstData!=NULL){
//free(lpDstData);
m_lpDstData=NULL;
}
if(m_lpMemData!=NULL){
//free(lpDstData);
m_lpMemData=NULL;
}
}