C++ Builder

Moderators: Lundin
Number of threads: 509
Number of posts: 1146

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Reading Bitmap data Posted by fp5149 on 4 May 2007 at 10:11 AM
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.
Report
Re: Reading Bitmap data Posted by zibadian on 4 May 2007 at 10:43 AM
: 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.
Report
Re: Reading Bitmap data Posted by MT2002 on 4 May 2007 at 2:52 PM
: 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.

This might help

Good luck;
Report
Re: Reading Bitmap data Posted by bilderbikkel on 5 May 2007 at 11:10 AM
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
Report
Re: Reading Bitmap data Posted by zibadian on 5 May 2007 at 11:24 AM
: 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.
Report
Re: Reading Bitmap data Posted by bilderbikkel on 6 May 2007 at 4:56 AM
: 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...

//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<unsigned char*>(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???
}
//---------------------------------------------------------------------------


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

See ya,
bilderbikkel



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.