Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Fast drawing directly to the Bitmap using C++

Status
Not open for further replies.

H_u_n_t_e_r

Full Member level 2
Full Member level 2
Joined
Nov 24, 2001
Messages
149
Helped
6
Reputation
12
Reaction score
2
Trophy points
1,298
Activity points
1,054
i have a buffer and i reading this buffer and trying to show on the screen with image control..for 25000 pixels consumes 2-3 second its very bad for me.

is there any efficient way of the following code

for(i=0;i>0;i++)
Image1->Canvas->Pixels[YY]= buffer;


could you suggest a book or tutorial fast graphic manuplation for borland c++ builder
Best Regards.
 

clearing a canvas in borland c++

i found this..
Code:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Graphics::TBitmap *pBitmap = new Graphics::TBitmap();
// This example shows drawing directly to the Bitmap
  Byte *ptr;
  try
  {
  //pBitmap->LoadFromFile("MyBitmap.bmp");
  pBitmap->Height=210;     pBitmap->Width=201;
    for (int y = 0; y < pBitmap->Height; y++)
    {
      ptr = (Byte *)pBitmap->ScanLine[y];
      for (int x = 0; x < pBitmap->Width; x++)

        ptr[x] = (Byte)x;
    }
  //Image1->Picture->Graphic = pBitmap; //
  Canvas->Draw(0,0,pBitmap);
  }
  catch (...)
  {
    ShowMessage("Could not load or alter bitmap");
  }
  delete pBitmap;
  }
but its slow..when i uncomment loadfile line and comment "pBitmap->Height=210; pBitmap->Width=201;" lines its very fast ..i dont understand whats going on?
 

rgbtriple +builder

What exactly do you want to do?

Paint the values in your array as a 1-D graph? Do the points in the array contain, for example, sine values?

Of does the array contain 2-D information? For example an image?

From your description it looks like the first case, but I'm not sure.

In the first example "for(i=0;i>0;i++)" looks a bit strange to me, as it will probably paint a lot more than 25000 pixels (assuming "i" is a 32 bit integer).

In the second example it is clear the everything goes very fast when you comment out the Width and Height setting, since the bitmap then will retain its original 0 by 0 pixel size. So the for loop following it will do no work at all.

So please clarify...
 

borland c++ graphics::tbitmap

Hi Gorilla, nice to see you again
i have a 511x511 buffer which its values filling by serial port.
then i want to show these values on the Image1 control. I dont have a image file so i dont need a loadfromfile function..
actually problem is simple "buffer to Image1 control" as fast as.
sorry for your time but i couldnt get good answers from anybody.
Greetings.
 

borland c++ builder tbitmap pixel

Windows, right? I don't know Borland Builder, but the good old Win32 method was to create your entire bitmap image in a memory buffer and then blit it to the screen by calling the Win32 API function BitBlt(). Search your compiler docs for keywords blit, bitblt, or bitblit.
 

borland c++ graphics

i ve solved my problem
i hope these codes helps to somebody..
problem was missing pixelformat line
pBitmap->PixelFormat = pf16bit; or 24bit

im using 16bit gray ...pf16bit is ok i think??????

Code:
Graphics::TBitmap *pBitmap = new Graphics::TBitmap;
       int i;
        try
        {
            pBitmap->PixelFormat = pf16bit;
            pBitmap->Height = 1000;
            pBitmap->Width = 1000;
           for(i=0;i<1;i++)
            for(int y = 0; y < pBitmap->Height; ++y)
            {
                RGBTRIPLE* ptr = (RGBTRIPLE *) pBitmap->ScanLine[y];
                for(int x = 0; x < pBitmap->Width; ++x)
                {
                    ptr[x].rgbtBlue = 255*x;
                    ptr[x].rgbtGreen = 255*x;
                    ptr[x].rgbtRed = 255*x;
                }
            }
            Image1->Picture->Graphic = pBitmap;
            Image1->Canvas->Refresh();
        }
        catch(const Exception &)
        {
            ShowMessage("Could not create bitmap");
        }
        delete pBitmap;
 

fast bitmap borland c++

Nice!

I'd say you need to create a 24 bits bitmap, that way each R, G, B value can range from 0-255 and with the shown code you'll get a grayscale bar (Edit: do change the "255*x" statements in simply "x").

With the 16 bits pixel format you get a colorfull pattern because the R, G and B values aren't the same number of bits.
 

make copy of bitmap graphics::tbitmap c++ borland

With the 16 bits pixel format you get a colorfull pattern because the R, G and B values aren't the same number of bits.

yes exactly!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top