See the question and my original answer on StackOverflow

You code works fine, but you must save the image back, for example like this

...
newImage->SetPropertyItem(propItem);

CLSID clsid;
GetEncoderClsid(L"image/jpeg", &clsid);
newImage->Save(L"Test2.jpg", &clsid);
...

BOOL GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
    UINT num = 0;
    UINT size = 0;
    ImageCodecInfo* info = NULL;

    ZeroMemory(pClsid, sizeof(CLSID));
    GetImageEncodersSize(&num, &size);
    if (size == 0)
        return FALSE;

    info = (ImageCodecInfo*)(malloc(size));
    if (info == NULL)
        return FALSE;

    GetImageEncoders(num, size, info);
    for (UINT j = 0; j < num; ++j)
    {
        if (!wcscmp(info[j].MimeType, format))
        {
            *pClsid = info[j].Clsid;
            free(info);
            return TRUE;
        }
    }

    free(info);
    return FALSE;
}