Board index » cppbuilder » RGB off Bitmap

RGB off Bitmap

I have the Bitmap loaded (Thanks to all who helped), but I can't seem to
get the correct rgb info off of scanLine. Some of the sample data looks
like this . . .   Where I'm I going wrong?

81b7cae0 81b7cae0 81b7cae0    81b7cae0 81b7cae0 81b7cae0    81b7cae0
81b7cae0 81b7cae0    81b7cae0 81b7cae0 81b7cae0    81b7cae0 81b7cae0
81b7cae0    81b7cae0 81b7cae0 81b7cae0

try
  {
    pBitmap->LoadFromFile("C:\\windows\\desktop\\blue.bmp ");
    for (int y = 0; y < pBitmap->Height; y++)
    {
      ptr = (byte *)pBitmap->ScanLine[y];

      for (int x = 0; x < pBitmap->Width; x++)
      {

      ptr[x] = (Byte)y;
      fprintf(outstream, "  %x  ", ptr);

      }
    }
    Canvas->Draw(0,0,pBitmap);

   }
  catch (...)
  {
    ShowMessage("Could not load or alter bitmap");
  }

  delete pBitmap;

 

Re:RGB off Bitmap


Quote
bill wrote:

> I have the Bitmap loaded (Thanks to all who helped), but I can't seem to
> get the correct rgb info off of scanLine. Some of the sample data looks
> like this . . .   Where I'm I going wrong?

> 81b7cae0 81b7cae0 81b7cae0    81b7cae0 81b7cae0 81b7cae0    81b7cae0
> 81b7cae0 81b7cae0    81b7cae0 81b7cae0 81b7cae0    81b7cae0 81b7cae0
> 81b7cae0    81b7cae0 81b7cae0 81b7cae0

<snip>

Here's what I would do (please ignore anything that's not applicable):
-------------------------------------------------------
    Graphics::TBitmap* pBitmap=new Graphics::TBitmap;
    byte* linePtr,*pixelPtr;

    char outString[256];

    pBitmap->LoadFromFile("ng.bmp");
    pBitmap->PixelFormat=pf24bit;

    for (int y = 0; y < pBitmap->Height; y++)
    {
      linePtr = (byte *)pBitmap->ScanLine[y];

      for (int x = 0; x < pBitmap->Width; x++)
      {
       pixelPtr = linePtr+3*x;
       sprintf(outString, "R: %d G: %d B: %d", pixelPtr[2], pixelPtr[1],
pixelPtr[0]);
      }
    }
    Canvas->Draw(0,0,pBitmap);
    delete pBitmap;
------------------------------------------------------

From looking at your code,

      ptr[x] = (Byte)y;

You were writing into the bitmap.  I haven't tried writing the results
to somewhere I can look at them; I just looked at the results with the
de{*word*81} (that's why I used sprintf).

There's some examples on my site that use ScanLine if you need them -
just go to the C++ Builder section.

Hope this helps,
Alan McIntyre
a...@norfolkgraphics.com
http://norfolkgraphics.com

Re:RGB off Bitmap


Hi

Your might be mixing it up a bit.
You get the pointer correct, ie ptr=(BYTE*)pBitmap->Scanline[y]
What you then do, is putting your Height counter (y) into the bitmap ?????
Not sure if thats what you want.

If the bitmap is 24 bit wide (You can alter this to fit your needs), ptr
points to the first Red value in the current line.
Data is organized as RGB, meaning that ptr[idx] will be valid for
idx<3*Width

So getting the RGB's from the bitmap would look something like

Red=ptr[idx];
Green=ptr[idx+1];
Blue=ptr[idx+2];
idx+=3;

And then loop Width times

If you assign data to ptr (as you do in your example), you have to manually
refresh the bitmap to see any changes.
Windows isnt aware of you altering pixels, so you must first make the bitmap
Dormant, and then Refresh it manually.

HTH
Lars

Quote
bill <stuart.b...@towerautomotive.com> wrote in message

news:376010D7.DA48CF99@towerautomotive.com...
Quote
> I have the Bitmap loaded (Thanks to all who helped), but I can't seem to
> get the correct rgb info off of scanLine. Some of the sample data looks
> like this . . .   Where I'm I going wrong?

> 81b7cae0 81b7cae0 81b7cae0    81b7cae0 81b7cae0 81b7cae0    81b7cae0
> 81b7cae0 81b7cae0    81b7cae0 81b7cae0 81b7cae0    81b7cae0 81b7cae0
> 81b7cae0    81b7cae0 81b7cae0 81b7cae0

> try
>   {
>     pBitmap->LoadFromFile("C:\\windows\\desktop\\blue.bmp ");
>     for (int y = 0; y < pBitmap->Height; y++)
>     {
>       ptr = (byte *)pBitmap->ScanLine[y];

>       for (int x = 0; x < pBitmap->Width; x++)
>       {

>       ptr[x] = (Byte)y;
>       fprintf(outstream, "  %x  ", ptr);

>       }
>     }
>     Canvas->Draw(0,0,pBitmap);

>    }
>   catch (...)
>   {
>     ShowMessage("Could not load or alter bitmap");
>   }

>   delete pBitmap;

Re:RGB off Bitmap


Quote
bill <stuart.b...@towerautomotive.com> wrote in message

news:376010D7.DA48CF99@towerautomotive.com...

Quote
> I have the Bitmap loaded (Thanks to all who helped), but I can't seem to
> get the correct rgb info off of scanLine.

The layout of a Scanline depends on the PixelFormat.  This Scanline Tech Note
explains the layout of a Scanline by PixelFormat:

http://www.efg2.com/lab/ImageProcessing/Scanline.htm

efg
_________________________________
efg's Computer Lab:  http://www.efg2.com/lab
Delphi Books:  http://www.efg2.com/lab/TechBooks/Delphi.htm

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

Other Threads