zoukankan      html  css  js  c++  java
  • TWICImage.SaveToStream内存泄漏的解决办法

    这个BUG从2010到XE5一直没改.....只能自己写个函数来搞了

    uses
        ActiveX;
    
    procedure WICImageSaveToStream(AWICImage: TWICImage; AStream: TStream);
    var
      nEncoder: IWICBitmapEncoder;
      nFrame: IWICBitmapFrameEncode;
      nProps: IPropertyBag2;
      nLStreamAdapter: TStreamAdapter;
      nPixelFormat: TGUID;
      nLStream: IWICStream;
      nPalette: IWICPalette;
      nData: TMemoryStream;
    begin
      nData:=TMemoryStream.Create;
      nLStreamAdapter := TStreamAdapter.Create(nData);
      IUnknown(nLStreamAdapter)._AddRef;
      try
        nData.Clear;
        AWICImage.ImagingFactory.CreateStream(nLStream);
        nLStream.InitializeFromIStream(nLStreamAdapter);
        AWICImage.ImagingFactory.CreateEncoder(AWICImage.EncoderContainerFormat, guid_null, nEncoder);
        nEncoder.Initialize(nLStream, WICBitmapEncoderNoCache);
        nEncoder.CreateNewFrame(nFrame, nProps);
        nFrame.Initialize(nProps);
        AWICImage.Handle.GetPixelFormat(nPixelFormat);
        nFrame.SetPixelFormat(nPixelFormat);
        nFrame.SetSize(AWICImage.Width, AWICImage.Height);
        AWICImage.ImagingFactory.CreatePalette(nPalette);
        AWICImage.Handle.CopyPalette(nPalette);
        nFrame.SetPalette(nPalette);
        nFrame.WriteSource(AWICImage.Handle, nil);
        nFrame.Commit;
        nEncoder.Commit;
        nData.Position := 0;
        AStream.CopyFrom(nData, nData.Size);
      finally
        IUnknown(nLStreamAdapter)._Release; {相对于VCL代码 , 这里要释放}
        nData.Free;
      end;
    end;
  • 相关阅读:
    表、索引元信息的更新
    接口
    SAP ALV OO 选择行打印
    SAP SMARTFORM 变量显示技巧
    SAP SMARTFORMS-基于内存方式在report程序中传递数据到smartforms显示
    PL/Proxy介绍
    pgpool介绍和安装经验
    pgbouncer介绍
    Hibernate使用时需要注意的几个小问题
    JDBC连接MySQL
  • 原文地址:https://www.cnblogs.com/lzl_17948876/p/3327878.html
Copyright © 2011-2022 走看看