CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2008
    Posts
    13

    Question TBitmap & TMemoryStream issue

    TMemoryStream *mem = new TMemoryStream();
    mem->LoadFromFile("c:\\image.bmp");

    BYTE *data = (BYTE *) malloc(mem->Size);

    memcpy(data,mem->Memory,mem->Size);
    int size = mem->Size;

    mem->Clear();
    mem->Write(data,size);



    Graphics::TBitmap *bmp = new Graphics::TBitmap;
    bmp->LoadFromStream(mem);


    for(int i = 0; i < 48 ; i++)
    {
    for(int k = 0; k < 192; k++)
    {
    Image1->Canvas->Pixels[k][i+50] = bmp->Canvas->Pixels[k][i];
    }
    }


    i am writing a dll for a project.
    one of the function need to get bitmap file in an array as parameter
    and do some operations on it,

    so i tried to do this on a form application first
    i am using TMemoryStream to load bitmap;


    so i need TMemoryStream to be loaded from BYTE array.

    i decided to load a TMemoryStream from a file,
    write it to BYTE array
    and write back it to Stream.

    when i load the bitmap it is just black.
    if i don't include array part (save and load back)
    everything is ok.

    so i wonder same data is in Stream,
    why bitmap is all black?

    anybody have an idea?

  2. #2
    Join Date
    Jun 2008
    Posts
    13

    Re: TBitmap & TMemoryStream issue

    got it!
    just don't forget to set position of TMemoryStream to "0" after operations

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured