How to create a lossless jpg using WIC in Delphi

前端 未结 1 935
无人共我
无人共我 2021-01-22 08:08

I have the following code working to create a jpg file out of a IWICBitmapSource with defaults options:

function SaveWICBitmapToJpgFile(WICFactory: IWICImagingFa         


        
相关标签:
1条回答
  • 2021-01-22 08:38

    I've no experience of this, but here's my best suggestions based on reading the documentation that you have linked to.

    First of all, I think you need to specify more of the members of PropBagOptions:

    • dwType needs to be set to PROPBAG2_TYPE_DATA.
    • vt needs to be set to VT_R4.

    You also need to make sure that the variant really is VT_R4. That's a 4 byte real, in Delphi terms a variant of type varSingle.

    V := VarAsType(1.0, varSingle);
    

    I think that should get it done.

    Putting it all together, it looks like this:

    FillChar(PropBagOptions, SizeOf(PropBagOptions), 0);
    PropBagOptions.pstrName := 'ImageQuality';
    PropBagOptions.dwType := PROPBAG2_TYPE_DATA;
    PropBagOptions.vt := VT_R4;
    V := VarAsType(1.0, varSingle);
    hr := PropBag.Write(1, @PropBagOptions, @V);
    

    As regards whether or not JPEG quality 1.0 is lossless, it is not. That's a question already well covered here: Is JPEG lossless when quality is set to 100?

    0 讨论(0)
提交回复
热议问题