关于如何在此图像上完成90度旋转的任何想法?以下是我的代码片段。
HWND hwnd = GetActiveWindow();
HMODULE hmod = GetModuleHandle(NULL);
HRSRC hResInfo = FindResource(hmod,MAKEINTRESOURCE(IDR_JPEG2),_T("JPEG"));
DWORD imagesize = SizeofResource(hmod,hResInfo);
HGLOBAL hResData = LoadResource(hmod,hResInfo);
if(hResData == NULL)
return -1;
LPVOID resptr = LockResource(hResData);
IImagingFactory *imgF = NULL;
IImage *iimg = NULL;
HDC hdc = pDC->GetSafeHdc();
int iWidth = GetSystemMetrics(SM_CXSCREEN);
int iHeight = GetSystemMetrics(SM_CYSCREEN);
::CoInitializeEx(NULL, ::COINIT_MULTITHREADED);//Initializing the COM object. It is required before
if (CoCreateInstance(CLSID_ImagingFactory,NULL,CLSCTX_INPROC_SERVER,IID_IImagingFactory,(void **)&imgF) == S_OK)
{
HRESULT hresult = imgF->CreateImageFromBuffer(resptr,imagesize,BufferDisposalFlagNone,&iimg);
RECT rect;
rect.bottom = iHeight;
rect.left = 0;
rect.right = iWidth;
rect.top = 0;
if(iWidth > iHeight)
{
//Rotation should take place here
}
iimg->Draw(hdc,&rect,NULL);
}
此函数的参数类型为CDC* pDC
。
答案 0 :(得分:6)
这很容易做到:
我希望这会对你有所帮助
答案 1 :(得分:2)
添加@ kids_fox的答案。这就是我完成旋转所做的。希望这可以帮助任何已经/正在/将要面对这个问题的人。将其添加到问题中的函数中。
IImage *pImage = NULL,
IBitmapImage *pBitmap = NULL;
IBitmapImage *pBitmapRotated = NULL; //Rotated Bitmap
IBasicBitmapOps *pBasicBitmapOps = NULL; //BitmapOps
HRESULT hr = S_FALSE
if(pImgFactory->CreateBitmapFromImage(iimg ,0,0,PixelFormatDontCare,InterpolationHintDefault,&pBitmap) == S_OK)
{
if(pBitmap->QueryInterface( IID_IBasicBitmapOps, (void**)&pBasicBitmapOps ) == S_OK)
{
if(pBasicBitmapOps->Rotate( rotateDegree, InterpolationHintBilinear, &pBitmapRotated) == S_OK)
{
hr = pBitmapRotated->QueryInterface(IID_IImage, ( void**)&pImage);
pBitmapRotated->Release();
pBitmapRotated = NULL;
}
pBasicBitmapOps->Release();
pBasicBitmapOps = NULL;
}
pBitmap->Release();
pBitmap = NULL;
}
//Now Draw the image
pImage->Draw(hdc,&rect,NULL);