如何将char *转换为TMemorystream *类型? [英] how to convert char * to TMemorystream * type?

查看:78
本文介绍了如何将char *转换为TMemorystream *类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1.如何将char *保存到图像文件中?

2.如何将char *转换为TMemorystream *类型?



1.how to save char * to a image file?
2.how to convert char * to TMemorystream * type?

void process(char* data, int length)
{
   //the data is a image
}





我尝试按照代码,但显示空白照片。





I have try follow code,but display a blank photo.

TMemoryStream * MemoryImageStream=new TMemoryStream;
  MemoryImageStream->Position=0;
  MemoryImageStream->Write(photo,len);

推荐答案

您需要为TMemoryImageStream对象指定适当的大小。



而不是:



You need to assign the appropriate size to the TMemoryImageStream object.

Instead of:

TMemoryStream * MemoryImageStream=new TMemoryStream;
    MemoryImageStream->Position=0;
    MemoryImageStream->Write(photo,len);





更改为:





change it to:

TMemoryStream * MemoryImageStream=new TMemoryStream(len);
    MemoryImageStream->Position=0;
    MemoryImageStream->Write(photo,len);





参见:

< a href =http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1> http ://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx?cs-save-lang = 1& cs-lang = cpp#code-snippet-1 [ ^ ]


这篇关于如何将char *转换为TMemorystream *类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆