I have read every resource I can find, and cannot make this work. I can read an image file into an IWICBitmap, convert it to an ID2D1Bitmap, and view it, all day long. But what I want to do is rotate the IWICBitmap 180 degrees, and store it back on disk. This is eluding me. Here is some code that reads an image from a file, and this works completely fine:
IWICFormatConverter* pWICConv = NULL; IWICBitmapDecoder* pWICDecoder = NULL; IWICBitmapFrameDecode* pWICBmpSrc = NULL; //Create a decoder. HRESULT hr = mpWICFactory->CreateDecoderFromFilename( (LPCWSTR)FullPath, NULL, GENERIC_READ, WICDecodeMetadataCacheOnLoad, &pWICDecoder); //Retrieve frame '0' and put it in pWICBmpSrc. if (SUCCEEDED(hr)) hr = pWICDecoder->GetFrame(0, &pWICBmpSrc); /*Create a format converter using the IWICImagingFactory to convert the image data from one pixel format to another, etc.*/ if (SUCCEEDED(hr)) hr = mpWICFactory->CreateFormatConverter(&pWICConv); /*Initialize the format converter with all sorts of information, including the frame that was decoded above.*/ if(SUCCEEDED(hr)) hr = pWICConv->Initialize(pWICBmpSrc, mPixelFormatWIC, WICBitmapDitherTypeNone, NULL, 0.f, WICBitmapPaletteTypeMedianCut); //Create the WICBitmap (mpImgWIC) from the Bitmap source hr = mpWICFactory->CreateBitmapFromSource( pWICConv, WICBitmapCacheOnLoad,&mpImgWIC);
The code above works great. I can load images using IWICBitmap all day long, convert them to ID2D1Bitmaps, and view them, no problem. But I here is the EXACT same code with a quick section inserted to rotate the IWICBitmap by 180 degrees.
IWICFormatConverter* pWICConv = NULL; IWICBitmapDecoder* pWICDecoder = NULL; IWICBitmapFrameDecode* pWICBmpSrc = NULL; //Create a decoder. HRESULT hr = mpWICFactory->CreateDecoderFromFilename( (LPCWSTR)FullPath, NULL, GENERIC_READ, WICDecodeMetadataCacheOnLoad, &pWICDecoder); //Retrieve frame '0' and put it in pWICBmpSrc. if (SUCCEEDED(hr)) hr = pWICDecoder->GetFrame(0, &pWICBmpSrc); /*Create a format converter using the IWICImagingFactory to convert the image data from one pixel format to another, etc.*/ if (SUCCEEDED(hr)) hr = mpWICFactory->CreateFormatConverter(&pWICConv); /*Initialize the format converter with all sorts of information, including the frame that was decoded above.*/ if(SUCCEEDED(hr)) hr = pWICConv->Initialize(pWICBmpSrc, mPixelFormatWIC, WICBitmapDitherTypeNone, NULL, 0.f, WICBitmapPaletteTypeMedianCut); /////////////////////////////////////////////////// /*This new section fails to do anything, but hr comes back S_OK in both instances*/ IWICBitmapFlipRotator *FlipRotator = NULL; if (SUCCEEDED(hr)) hr = mpWICFactory->CreateBitmapFlipRotator(&FlipRotator); if (SUCCEEDED(hr)) hr = FlipRotator->Initialize(pWICConv, WICBitmapTransformRotate180); /////////////////////////////////////////////////// //Create the WICBitmap (mpImgWIC) from the Bitmap source hr = mpWICFactory->CreateBitmapFromSource( pWICConv, WICBitmapCacheOnLoad,&mpImgWIC);
Can anyone tell me what I'm doing wrong?
Thanks!