我已经成功地将图像加载到Windows成像组件中,但我陷入了最后一步,我如何保存现在在PWICBITMAP变量中可用的图像。
。我也想知道是否低于翻转位图映像的好方法?
这是我的代码:
IWICImagingFactory *pIWICFactory = NULL;
IWICFormatConverter* pWICConv = NULL; //WIC converter
IWICBitmapDecoder *pIDecoder = NULL;
IWICBitmapFrameDecode *pIDecoderFrame = NULL;
IWICBitmapFlipRotator *pIFlipRotator = NULL;
IWICBitmap *pWICBitmap = NULL;
CoInitializeEx(0, COINIT_MULTITHREADED);
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pIWICFactory)
);
hr = pIWICFactory->CreateDecoderFromFilename(
//(LPCWSTR)pszBMPFilePath, // Image to be decoded
L"Bitmap.bmp",
NULL, // Do not prefer a particular vendor
GENERIC_READ, // Desired read access to the file
WICDecodeMetadataCacheOnDemand, // Cache metadata when needed
&pIDecoder // Pointer to the decoder
);
if (SUCCEEDED(hr))
{
hr = pIDecoder->GetFrame(0, &pIDecoderFrame);
}
//Create a format converter using the IWICImagingFactory to convert the
//image data from one pixel format to another, handling dithering and
//halftoning to indexed formats, palette translation and alpha thresholding.
if (SUCCEEDED(hr)) {
hr = pIWICFactory->CreateFormatConverter(&pWICConv);
}
//Initialize the format converter with all sorts of information, including the frame that was
//decoded above
if (SUCCEEDED(hr))
hr = pWICConv->Initialize(pIDecoderFrame,
GUID_WICPixelFormat32bppPBGRA, // Destination pixel format
WICBitmapDitherTypeNone,
NULL,
0.f,
WICBitmapPaletteTypeMedianCut);
if (SUCCEEDED(hr))
{
hr = pIWICFactory->CreateBitmapFlipRotator(&pIFlipRotator);
}
// Initialize the flip/rotator to flip the original source horizontally.
if (SUCCEEDED(hr))
{
//hr = pIFlipRotator->Initialize(
// pIDecoderFrame, // Bitmap source to flip.
// WICBitmapTransformFlipHorizontal); // Flip the pixels along the vertical y-axis.
hr = pIFlipRotator->Initialize(
pWICConv, // Bitmap source to flip.
WICBitmapTransformFlipHorizontal); // Flip the pixels along the vertical y-axis.
/*hr = pIFlipRotator->Initialize(
pIDecoderFrame,
WICBitmapTransformFlipVertical);*/
/*hr = pIFlipRotator->Initialize(
pIDecoderFrame,
WICBitmapTransformRotate180);*/
}
//Create the WICBitmap (mpImgWIC) from the Bitmap source (WIC Flip rotator)
hr = pIWICFactory->CreateBitmapFromSource(pIFlipRotator, WICBitmapCacheOnLoad, &pWICBitmap);
创建WicbitMap是不需要的。iwicbitmapfliprotator是一个iWicbitMapsource,您可以使用它来创建图像。
您需要创建一个iwicbitmapencencoder和iwicbitmapframeencode对象。
MSDN在这里有一个示例:https://msdn.microsoft.com/en-us/library/windows/desktop/gg430021(v = vs.85).aspx
MSDN的示例预计您将手动提供图像数据,但是您可以使用iwicbitmapframeencode :: Writesource方法直接从iwicbitmapfliprotator写入:桌面/EE690159(v = vs.85).aspx