Jump to content

Scanline in Borland

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Guest_tommy_mm_*

Guest_tommy_mm_*
  • Guests
In Borland C++
I have copied an Image1 to an array tab[x][y], now i wnant to copy pixels from that array to Image2 using ScanLine.

I have used code:

int tab[256][256], *LinePtr; 

void __fastcall TForm1::Button2Click(TObject *Sender) 
{ 
for (int y=0; y<255; y++) 
{ 
LinePtr = (BYTE *) Image2->Picture->Bitmap->ScanLine[y]; 
for (int x=0; x<255; x++) 
{ 
LinePtr[x*3] = tab[x][y]; 
LinePtr[x*3+1] = tab[x][y]; 
LinePtr[x*3+2] = tab[x][y]; 
} 
} 
Image2->Refresh(); 
} 

But the image I have received is gray. The original one was colorful.
How to use Scanline to receive original copied picture?

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I don't know enough about it to help you but I did find this:
efg's Tech Note: Manipulating Pixels With Delphi's ScanLine Property

WingedPanther uses Borland I believe (I may be wrong). He may be able to help you further.

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Just looking at a few things: LinePtr points to int, but you are assigning it pointers to bytes. This could cause issues.

the code from the 2006 Borland help has this example:
[C++]
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Graphics::TBitmap *pBitmap = new Graphics::TBitmap();
// This example shows drawing directly to the Bitmap
Byte *ptr;
try
{
pBitmap->LoadFromFile("C:\\Program Files\\Borland\\CBuilder\\Images\\Splash\\256color\
\factory.bmp ");
for (int y = 0; y < pBitmap->Height; y++)
{
ptr = pBitmap->ScanLine[y];
for (int x = 0; x < pBitmap->Width; x++)
ptr[x] = (Byte)y;
}
Canvas->Draw(0,0,pBitmap);
}
catch (...)
{
ShowMessage("Could not load or alter bitmap");
}
delete pBitmap;
}

It just seems to be a difference of RGB element by RGB element vs color by color.

Third: you appear to be setting the R, G, and B values all to tab[x][y], which would be a shade of grey.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog