这个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 := ;
AStream.CopyFrom(nData, nData.Size);
finally
IUnknown(nLStreamAdapter)._Release; {相对于VCL代码 , 这里要释放}
nData.Free;
end;
end;