首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用WIC将QImage编码为png?

使用WIC将QImage编码为png?
EN

Stack Overflow用户
提问于 2014-04-16 10:10:32
回答 1查看 746关注 0票数 0

我正在尝试测试WIC和QT中的编码函数之间的性能。但是我找不到一种使用WIC从QImage (QT对象)编码到PNG的方法。

需要从IStream中初始化来自WIC的编码器,它应该提供与图像文件相同的数据。但我有的是位图。

有人能帮我吗?如有任何意见,将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-22 12:56:55

这是很容易做到的。我不知道如何使用编码器。IWICBitmapFrameEncode.WritePixels是我应该放置原始像素的地方:

代码语言:javascript
复制
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();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23106339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档