GDI+中Image对象如何保存到IStream中?

NBTestNC 2012-05-22 04:10:54
RT
调用函数我知道是使用save,例如
// 假如有个Image对象image。我是这样写的

IStream * pIStream = NULL;
CLSID encoderClisid;
GetEncoderClsid(L"image/bmp",&encoderClisid);
image.save(pIStream,&encoderClis,NULL);
// 程序执行不对
...全文
162 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
NBTestNC 2012-05-22
  • 打赏
  • 举报
回复
嗯,我也是看的这个例子,模仿出来了,不过又遇到新的问题了,算了GDI+太讨厌了,不用了!
大海啊全是水 2012-05-22
  • 打赏
  • 举报
回复

Status MakeCompoundFile()
{
IStorage* pIStorage = NULL;
IStream* pIStream1 = NULL;
IStream* pIStream2 = NULL;
HRESULT hr;
Status stat = Ok;

// Create two Image objects from existing files.
Image image1(L"Crayons.jpg");
Image image2(L"Mosaic.png");

hr = CoInitialize(NULL);
if(FAILED(hr))
goto Exit;

// Create a compound file object, and get
// a pointer to its IStorage interface.
hr = StgCreateDocfile(
L"CompoundFile.cmp",
STGM_READWRITE|STGM_CREATE|STGM_SHARE_EXCLUSIVE,
0,
&pIStorage);

if(FAILED(hr))
goto Exit;

// Create a stream in the compound file.
hr = pIStorage->CreateStream(
L"StreamImage1",
STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
0,
0,
&pIStream1);

if(FAILED(hr))
goto Exit;

// Create a second stream in the compound file.
hr = pIStorage->CreateStream(
L"StreamImage2",
STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
0,
0,
&pIStream2);

if(FAILED(hr))
goto Exit;

// Get the class identifier for the JPEG encoder.
CLSID jpgClsid;
GetEncoderClsid(L"image/jpeg", &jpgClsid);

// Get the class identifier for the PNG encoder.
CLSID pngClsid;
GetEncoderClsid(L"image/png", &pngClsid);

// Save image1 as a stream in the compound file.
stat = image1.Save(pIStream1, &jpgClsid);
if(stat != Ok)
goto Exit;

// Save image2 as a stream in the compound file.
stat = image2.Save(pIStream2, &pngClsid);

Exit:
if(pIStream1)
pIStream1->Release();
if(pIStream2)
pIStream2->Release();
if(pIStorage)
pIStorage->Release();

if(stat != Ok || FAILED(hr))
return GenericError;

return Ok;
}


MSDN上面的例子
你执行错误的原因 应该是你的pIStream 是NULL。。。 看例子吧
NBTestNC 2012-05-22
  • 打赏
  • 举报
回复

来人啊!
NBTestNC 2012-05-22
  • 打赏
  • 举报
回复
UP啊,难道没人吗?

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧