Reading Bitmap data

Hello Everyone,

I am using Borland C++ Builder 3.0 for my term project.I need to read the data in a bitmap file and store it in a matrix. Is there any function that can enable me to do this? if there is none, can anyone help me out on how i could acheive this?

Thanks a lot
fp5149.

Comments

  • : Hello Everyone,
    :
    : I am using Borland C++ Builder 3.0 for my term project.I need to
    : read the data in a bitmap file and store it in a matrix. Is there
    : any function that can enable me to do this? if there is none, can
    : anyone help me out on how i could acheive this?
    :
    : Thanks a lot
    : fp5149.
    :
    In Delphi there is a TBitmap object, which allows access to nearly everything of a bitmap. I expect a similar object in C++ to be present also. If it exists, it should be listed in the help files.
  • : Hello Everyone,
    :
    : I am using Borland C++ Builder 3.0 for my term project.I need to
    : read the data in a bitmap file and store it in a matrix. Is there
    : any function that can enable me to do this? if there is none, can
    : anyone help me out on how i could acheive this?
    :
    : Thanks a lot
    : fp5149.
    :
    You can try the Win32 API LoadImage() routine, if possible.

    [link=http://www.gamedev.net/reference/articles/article1966.asp]This might help[/link]

    Good luck;
  • Try using ScanLine on a TImage with a bitmap loaded in it, see
    http://www.codepedia.com/1/CppVclScanLine
    or
    http://www.codepedia.com/1/CppVclGraphics

    Good luck,
    bilderbikkel
  • : Try using ScanLine on a TImage with a bitmap loaded in it, see
    : http://www.codepedia.com/1/CppVclScanLine
    : or
    : http://www.codepedia.com/1/CppVclGraphics
    :
    : Good luck,
    : bilderbikkel
    You do not necessarily need to use a TImage. The advantage of creating a TBitmap object directly is that the GUI doesn't need to be used. This can especially create a speed optimalization if the image gets changed.
  • : You do not necessarily need to use a TImage. The advantage of
    : creating a TBitmap object directly is that the GUI doesn't need to
    : be used. This can especially create a speed optimalization if the
    : image gets changed.

    Hi zibadian,

    Thanks for your reply! You are right and I wish I could do it the right way. But in C++ Builder I can't get this right way to work! I posted multiple times about this subject already. The problem lies in assigning the TBitmap* to the TImage*. If you can get the function 'AssignBitmapTImage' below working, I would have bought you a beer if you would live somewhere near :-). No hard feelings though, if you have higher priorities...

    [code]
    //Needed on the Form:
    //* A TButton called Button1
    //* A TImage called Image1

    void DoCoolEffect(Graphics::TBitmap * const bitmap)
    {
    const int maxx = bitmap->Width;
    const int maxy = bitmap->Height;
    for (int y = 0; y != maxy; ++y)
    {
    unsigned char * const myLine = static_cast(bitmap->ScanLine[y]);
    for (int x = 0; x != maxx; ++x)
    {
    myLine[x*3+2] = (x+0) % 256; //Red
    myLine[x*3+1] = (y+0) % 256; //Green
    myLine[x*3+0] = (x+y) % 256; //Blue
    }
    }
    }
    //---------------------------------------------------------------------------

    void AssignBitmapToImage(Graphics::TBitmap * const bitmap,TImage * const image)
    {
    image->Width = bitmap->Width;
    image->Height = bitmap->Height;
    //Does not work:
    //image->Picture->Assign(bitmap);
    image->Picture->Bitmap = bitmap;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    const int maxx = 256;
    const int maxy = 256;
    Graphics::TBitmap * bitmap = new Graphics::TBitmap;
    bitmap->Width = maxx;
    bitmap->Height = maxy;
    DoCoolEffect(bitmap);
    AssignBitmapToImage(bitmap,Image1);

    assert(bitmap->Width == Image1->Width);
    assert(bitmap->Height == Image1->Height);
    #ifndef NDEBUG
    for (int y=0; y!=maxy; ++y)
    {
    for (int x=0; x!=maxx; ++x)
    {
    assert(bitmap->Canvas->Pixels[0][0] == Image1->Canvas->Pixels[0][0]);
    }
    }
    #endif

    Image1->Visible = true;
    Image1->Refresh();
    //Delete necessary???
    }
    //---------------------------------------------------------------------------
    [/code]

    The result will be a white square as if the GUI does not know what happened 'behind the scenes'...

    See ya,
    bilderbikkel
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories