Roger Alcindor
asked on
Pixel image reversal problem
I have copied an example of a mirror image generator from Delphi.com with a view to using it in a C++ builder project.
I get the following error in the iteration of the for loop:
First chance exception at $74CBC5AF. Exception class EInvalidOperation with message 'Can only modify an image if it contains a bitmap'. Process BitmapMirror.exe (7408)
The code is as follows:
I get the following error in the iteration of the for loop:
First chance exception at $74CBC5AF. Exception class EInvalidOperation with message 'Can only modify an image if it contains a bitmap'. Process BitmapMirror.exe (7408)
The code is as follows:
void __fastcall TForm1::Button1Click(TObject *Sender)
{ // load an image file into Image1
// reverse the horizontal image (make a mirror image) and display in Image2
TBitmap *bm;
int i,j;
TColor c;
if(OpenDialog1->Execute())
{
Image1->Picture->LoadFromFile(OpenDialog1->FileName);
}
bm = new TBitmap();
bm->Height = Image1->Height;
bm->Width = Image1->Width;
for(i=0;i< Image1->Width;i++)
for(j=0;j<Image1->Height;j++)
bm->Canvas->Pixels[Image1->Width-i][j] = Image1->Canvas->Pixels[i][j]; // <<<<< This line produces the run-time error
Image2->Picture->Assign(bm);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER