【发布时间】:2014-06-17 23:19:51
【问题描述】:
我正在尝试测试 WIC 和 QT 的编码功能之间的性能。但我找不到使用 WIC 从 QImage(QT 对象)编码为 PNG 的方法。
来自 WIC 的编码器需要从 IStream 初始化,它应该提供与图像文件相同的数据。但我所拥有的是一种位图。
谁能帮帮我?任何意见将不胜感激。
【问题讨论】:
我正在尝试测试 WIC 和 QT 的编码功能之间的性能。但我找不到使用 WIC 从 QImage(QT 对象)编码为 PNG 的方法。
来自 WIC 的编码器需要从 IStream 初始化,它应该提供与图像文件相同的数据。但我所拥有的是一种位图。
谁能帮帮我?任何意见将不胜感激。
【问题讨论】:
这很容易做到。我不知道如何使用编码器。 IWICBitmapFrameEncode.WritePixels 是我应该放置原始像素的地方:
factory = CreateComObject(CLSID_WICImagingFactory);
IWICBitmapEncoder pngEncoder = factory.CreateEncoder(GUID_ContainerFormatPng, null);
pngEncoder.Initialize(targetStream, WICBitmapEncoderNoCache);
IPropertyBag2 propertyBag;
IWICBitmapFrameEncode frame = pngEncoder.CreateNewFrame(ref propertyBag);
frame.Initialize(propertyBag);
//Set the size of the image
frame.SetSize(640, 480);
//Request the encoder use this format.
Guid format = GUID_WICPixelFormat32bppPBGRA;
//If the encoder doesn't support that format, it will set format to the closest it does support
frame.SetPixelFormat(ref format);
//if the frame encoder doesn't support the pixel format we want to give it
//then we just cannot proceed
Assert(format == GUID_WICPixelFormat32bppPBGRA);
frame.WritePixels(
lineCount,
stride,
bufferSize,
pointerToPixelData);
frame.Commit();
pngEncoder.Commit();
【讨论】: