博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

BMP保存成string再进行显示

Posted on 2009-11-11 14:04  海岛  阅读(228)  评论(0编辑  收藏  举报
    ifstream in("c:\\Greenstone.bmp", ios::in|ios_base::binary);
    string s = string((istreambuf_iterator<char>(in)), istreambuf_iterator<char>());
    TMemoryStream* ms = new TMemoryStream();
    ms->Write(s.c_str(), s.length());
    ms->Position = 0;
    in.close();
    Graphics::TBitmap* bitmap = new Graphics::TBitmap();
    bitmap->LoadFromStream(ms);
    this->Image1->Canvas->StretchDraw(Rect(0,0,this->Image1->Width, this->Image1->Height), bitmap);
    delete bitmap;
    bitmap = 0;
    delete ms;
    ms = 0;