2017-02-17 13 views
0

아래 이미지를 Windows Imaging 구성 요소에 성공적으로로드했습니다.하지만 마지막 단계에서 멈추었습니다. , pWICBitmap 변수에서 현재 사용 가능한 이미지를 어떻게 저장합니까?Windows 이미징 구성 요소를 사용하여 32 비트 이미지를로드하고 뒤집어서 동일한 파일에 다시 저장하려고합니다.

또한 아래의 좋은 방법이면 비트 맵 이미지를 뒤집을 수 있는지 알고 싶습니까? WICBitmap 만들기 필요가 없습니다

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); 

답변

0

:

여기 내 코드입니다. IWICBitmapFlipRotator는 이미지를 만드는 데 사용할 수있는 IWICBitmapSource입니다.

IWICBitmapEncoder 및 IWICBitmapFrameEncode 개체를 만들어야합니다. https://msdn.microsoft.com/en-us/library/windows/desktop/gg430021(v=vs.85).aspx

MSDN의 예제는 수동으로 이미지 데이터를 제공 할 것으로 기대하고 있지만, 직접 IWICBitmapFlipRotator에서 작성하는 IWICBitmapFrameEncode :: WriteSource 방법을 사용할 수 있습니다 :

MSDN은 여기에 예제가 https://msdn.microsoft.com/en-us/library/windows/desktop/ee690159(v=vs.85).aspx