2014-05-17 2 views
2

기본 이미지 변환기를 프로그래밍하여 이미지를 BMP로 변환합니다. 나는 메모리 누출을 피하기 위해 마지막에 Image를 정리했다. 나는 그것을 컴파일 할 때,이 오류가 온다 최대 : 나는 여러 웹 사이트를 확인하지만 때 한GDI + 이미지를 삭제할 수 없습니다.

'클래스에는 GDIPlus :: 이미지'인수는 '삭제'에게 주어진

유형, 예상 포인터 그들의 예제를 사용하지만, 여전히 컴파일러 오류가 발생합니다. Microsoft의 예조차도 그 오류가 떠오른다! 이미지를 삭제할 수있는 방법이 포함 된 웹 사이트를 보았지만 이미지를 삭제 한 링크 나 방법을 기억할 수 없습니다.

내 코드 : 당신이 나에게 작동하는 대답을하는 경우

#include <windows.h> 
#include <gdiplus.h> 

using namespace Gdiplus; 

int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) 
{ 
    using namespace Gdiplus; UINT num = 0;   // number of image encoders 
    UINT size = 0;   // size of the image encoder array in bytes 

    ImageCodecInfo* pImageCodecInfo = NULL; 

    GetImageEncodersSize(&num, &size); 
    if(size == 0) 
     return -1; // Failure 

    pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); 
    if(pImageCodecInfo == NULL) 
    return -1; // Failure 

    GetImageEncoders(num, size, pImageCodecInfo); 

    for(UINT j = 0; j < num; ++j) 
    { 
     if(wcscmp(pImageCodecInfo[j].MimeType, format) == 0) 
     { 
      *pClsid = pImageCodecInfo[j].Clsid; 
      free(pImageCodecInfo); 
      return j; // Success 
     } 
    } 

    free(pImageCodecInfo); 
    return 0; 
} 


int main() 
{ 
    GdiplusStartupInput gdiplusStartupInput; 
    ULONG_PTR gdiplusToken; 
    CLSID bmpClsid; 
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); 
    Image picture(L"TEST.GIF"); 
    GetEncoderClsid(L"image/bmp", &bmpClsid); 
    picture.Save(L"Mosaic2.bmp", &bmpClsid, NULL); 
    delete picture; 
    GdiplusShutdown(gdiplusToken); 
    return 0; 
} 

나는 프로그램의 크레딧에 넣을 것입니다. 감사합니다.

답변

3

음, delete은 포인터에서만 작동하며 "그림"은 개체입니다 (어떤 식 으로든 과부하가 발생하지 않는 한). 또한, 로컬 객체이기 때문에 메인의 마지막에 소멸자를 호출해야합니다 (로드 된 이미지를 포함하여 관련된 메모리를 해제해야 함). 그러나 메모리가 GdiplusShutdown(gdiplusToken); 전에 출시되어야하는 경우 포인터를 사용하도록 코드를 적용 할 수 있습니다.

Image *picture = new Image (L"TEST.GIF"); 
GetEncoderClsid(L"image/bmp", &bmpClsid); 
picture->Save(L"Mosaic2.bmp", &bmpClsid, NULL); 
delete picture; 
+1

이 코드는 이전 코드보다 빠르게 작동합니다! 나는 크레딧에 당신의 이름을 추가 할 것입니다. – TheNoob

관련 문제