How To Draw On Bitmap Then Copy to TImage?

How To Draw On Bitmap Then Copy to TImage?

Post by Jack Frosc » Thu, 13 Nov 1997 04:00:00



As so many have noted, using Image->Canvas-Pixels[x][y] is too slow to
be described as slow!  However, if I draw on the Canvas of a nonvisual
Bitmap object using Bitmap->Canvas->Pixels[x][y], the operation appears
to be quite fast, but I'm not sure why this is so.

It's amazing how much other stuff the app does in the blink of an eye
and how long it takes for that one Pixels operation.  Unfortunately,
Borland hasn't seen fit to provide a Profiler with BCB, but informal
timings look like 90+ % of the execution time was being used by the
Pixels assignment operation.

Is there a way to draw on a non-visual Bitmap object and then copy that
"drawing" to the canvas of the Image control?

Thanks.

 
 
 

How To Draw On Bitmap Then Copy to TImage?

Post by Jonathan Arnol » Fri, 14 Nov 1997 04:00:00


Quote:> be described as slow!  However, if I draw on the Canvas of a nonvisual
> Bitmap object using Bitmap->Canvas->Pixels[x][y], the operation appears
> to be quite fast, but I'm not sure why this is so.

This is the main "trick" of graphics programming - do all your work
offscreen, then copy the change bits to the screen.  As the Pixels
operation uses Get/SetPixel, which any programmer stays well away from
except in dire emergencies, doing it offscreen and then copying it to
the screen is the way to go.

Quote:> Is there a way to draw on a non-visual Bitmap object and then copy that
> "drawing" to the canvas of the Image control?

Sure, just look at the methods for TCanvas.  You can use StretchDraw,
or CopyRect or Draw...

+===================================================+

| Programmer                Roger Wagner Publishing |
| http://world.std.com/~jdarnold                    |
+===================================================+

 
 
 

How To Draw On Bitmap Then Copy to TImage?

Post by Jack Frosc » Fri, 14 Nov 1997 04:00:00


Jonathan,

Can you show me an example of using the Draw method?  Is the Bitmap
argument the local "offscreen" Bitmap, or do I have to assign that
Bitmap to the Picture property of the Image canvas?

Do I sound confused?  I am!

Thanks for your help.


> > be described as slow!  However, if I draw on the Canvas of a
> nonvisual
> > Bitmap object using Bitmap->Canvas->Pixels[x][y], the operation
> appears
> > to be quite fast, but I'm not sure why this is so.

> This is the main "trick" of graphics programming - do all your work
> offscreen, then copy the change bits to the screen.  As the Pixels
> operation uses Get/SetPixel, which any programmer stays well away from

> except in dire emergencies, doing it offscreen and then copying it to
> the screen is the way to go.

> > Is there a way to draw on a non-visual Bitmap object and then copy
> that
> > "drawing" to the canvas of the Image control?

> Sure, just look at the methods for TCanvas.  You can use StretchDraw,
> or CopyRect or Draw...

> +===================================================+

> | Programmer                Roger Wagner Publishing |
> | http://world.std.com/~jdarnold                    |
> +===================================================+

 
 
 

How To Draw On Bitmap Then Copy to TImage?

Post by Jack Frosc » Fri, 14 Nov 1997 04:00:00


Let me clarify what I've done, even though it doesn't yet work:

/***************************************************************************/

int                            iPixelColor;
Graphics::TBitmap    *Bitmap;

Bitmap = new Graphics::TBitmap;

for (int iRow = 0; iRow < FHeight; iRow++)
   for (int iCol = 0; iCol < FWidth; iCol++)
    {
    // PixelValues is an array of pointers to objects which contain info on
a pixel, including its grayscale color
    iPixelColor = PixelValues[iRow * iWidth + iCol]->getPixelColor();
    Bitmap->Canvas->Pixels[iCol][iRow] = (TColor) RGB(iPixelColor,
iPixelColor, iPixelColor);
    }

ImageCanvas->Draw(0, 0, Bitmap);        // all I get is a white Image, even
if I hardcode iPixelColor to clBlack

delete Bitmap;
/***************************************************************************/


> Jonathan,

> Can you show me an example of using the Draw method?  Is the Bitmap
> argument the local "offscreen" Bitmap, or do I have to assign that
> Bitmap to the Picture property of the Image canvas?

> Do I sound confused?  I am!

> Thanks for your help.


> > > be described as slow!  However, if I draw on the Canvas of a
> > nonvisual
> > > Bitmap object using Bitmap->Canvas->Pixels[x][y], the operation
> > appears
> > > to be quite fast, but I'm not sure why this is so.

> > This is the main "trick" of graphics programming - do all your work
> > offscreen, then copy the change bits to the screen.  As the Pixels
> > operation uses Get/SetPixel, which any programmer stays well away from

> > except in dire emergencies, doing it offscreen and then copying it to
> > the screen is the way to go.

> > > Is there a way to draw on a non-visual Bitmap object and then copy
> > that
> > > "drawing" to the canvas of the Image control?

> > Sure, just look at the methods for TCanvas.  You can use StretchDraw,
> > or CopyRect or Draw...

> > +===================================================+

> > | Programmer                Roger Wagner Publishing |
> > | http://world.std.com/~jdarnold                    |
> > +===================================================+

 
 
 

How To Draw On Bitmap Then Copy to TImage?

Post by Jonathan Arnol » Sat, 15 Nov 1997 04:00:00


Quote:> Let me clarify what I've done, even though it doesn't yet work:

Okay, here's what I did.  I created a simple form.  Dropped a button on
it and an Image.  In the button click method, I did this:

void __fastcall TForm1::DrawClick(TObject *Sender)
{
int                            iPixelColor;
Graphics::TBitmap    *Bitmap;

Bitmap = new Graphics::TBitmap;

Bitmap->Height = Image1->Height;
Bitmap->Width = Image1->Width;

for (int iRow = 0; iRow < Bitmap->Height; iRow++)
   for (int iCol = 0; iCol < Bitmap->Width; iCol++)
    {
    // PixelValues is an array of pointers to objects which contain info on
    // iPixelColor = PixelValues[iRow * iWidth + iCol]->getPixelColor();
    Bitmap->Canvas->Pixels[iCol][iRow] = (TColor) RGB(0,0,0); //iPixelColor, iPixelColor, iPixelColor);
    }

Image1->Canvas->Draw(0, 0, Bitmap);

delete Bitmap;

Quote:}

When I click the button, boom, a black square shows up.

The questions I have with what you posted are:

1) Where is this code?  What event causes it to happen?  Remember, once
you draw it on there, it will disappear whenever things need to get
refreshed (ahh, the wonders of windows).  So if you do this at startup,
it just won't be there.

2) What is PixelValues?  And if it is what it sounds like, it is already
an RGB value, so you can just put it into Pixels.

+===================================================+

| Programmer                Roger Wagner Publishing |
| http://world.std.com/~jdarnold                    |
+===================================================+

 
 
 

How To Draw On Bitmap Then Copy to TImage?

Post by Jack Frosc » Sat, 15 Nov 1997 04:00:00


Ugh.  I forgot to set the Height and Width properties.  It's working
okay now.  However, it's still a little slower than I'd like.  (Image is
765 x 510 pixels.)

At least it's working.  Thanks so much for your help.

Jack


> > Let me clarify what I've done, even though it doesn't yet work:

> Okay, here's what I did.  I created a simple form.  Dropped a button
> on
> it and an Image.  In the button click method, I did this:

> void __fastcall TForm1::DrawClick(TObject *Sender)
> {
> int                            iPixelColor;
> Graphics::TBitmap    *Bitmap;

> Bitmap = new Graphics::TBitmap;

> Bitmap->Height = Image1->Height;
> Bitmap->Width = Image1->Width;

> for (int iRow = 0; iRow < Bitmap->Height; iRow++)
>    for (int iCol = 0; iCol < Bitmap->Width; iCol++)
>     {
>     // PixelValues is an array of pointers to objects which contain
> info on
>     // iPixelColor = PixelValues[iRow * iWidth +
> iCol]->getPixelColor();
>     Bitmap->Canvas->Pixels[iCol][iRow] = (TColor) RGB(0,0,0);
> //iPixelColor, iPixelColor, iPixelColor);
>     }

> Image1->Canvas->Draw(0, 0, Bitmap);

> delete Bitmap;
> }

> When I click the button, boom, a black square shows up.

> The questions I have with what you posted are:

> 1) Where is this code?  What event causes it to happen?  Remember,
> once
> you draw it on there, it will disappear whenever things need to get
> refreshed (ahh, the wonders of windows).  So if you do this at
> startup,
> it just won't be there.

> 2) What is PixelValues?  And if it is what it sounds like, it is
> already
> an RGB value, so you can just put it into Pixels.

> +===================================================+

> | Programmer                Roger Wagner Publishing |
> | http://world.std.com/~jdarnold                    |
> +===================================================+

 
 
 

1. How to copy bitmap from TImage to TImageList

I want to copy the image in a TImage component into a TImageList.

The obvious method appears to be :

    ImageList->Add(Image->Picture->Bitmap, NULL);

but this generates an EInvalidOperation exception ("Invalid ImageList")

What am I doing wrong?

TIA

--
Gav
(Newbie alert!)

2. ?Preview Icons-? how to change?

3. How to get to TImage Canvas drawing bitmap

4. Newest Mathcad warez! COOL!

5. Copy a bitmap from a bitmap pointer

6. CorelDraw8 - urgent!

7. copy non-transparent pixels from bitmap to bitmap

8. My programs in DirectDraw sometimes reboot the pc...

9. TImage copy to canvas

10. How copy and restore in TImage

11. Copy Two or More Bitmaps to one TImage

12. How to copy HBITMAP to TImage ?

13. Copying TForm to TImage