+ Post New Thread
Results 1 to 8 of 8
  1. #1
    Full Member level 2
    Points: 3,634, Level: 14
    H_u_n_t_e_r's Avatar
    Join Date
    Nov 2001
    Posts
    149
    Helped
    6 / 6
    Points
    3,634
    Level
    14

    Fast drawing directly to the Bitmap using C++

    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[i][YY]= buffer[i];


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

    •   Alt17th October 2005, 08:23

      advertising

        
       

  2. #2
    Full Member level 2
    Points: 3,634, Level: 14
    H_u_n_t_e_r's Avatar
    Join Date
    Nov 2001
    Posts
    149
    Helped
    6 / 6
    Points
    3,634
    Level
    14

    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?



    •   Alt17th October 2005, 15:19

      advertising

        
       

  3. #3
    Member level 5
    Points: 3,715, Level: 14
    Gorilla's Avatar
    Join Date
    Jan 2003
    Posts
    89
    Helped
    9 / 9
    Points
    3,715
    Level
    14

    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...



    •   Alt18th October 2005, 19:48

      advertising

        
       

  4. #4
    Full Member level 2
    Points: 3,634, Level: 14
    H_u_n_t_e_r's Avatar
    Join Date
    Nov 2001
    Posts
    149
    Helped
    6 / 6
    Points
    3,634
    Level
    14

    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.



  5. #5
    Advanced Member level 5
    Points: 32,456, Level: 44

    Join Date
    Apr 2002
    Location
    USA
    Posts
    3,942
    Helped
    660 / 660
    Points
    32,456
    Level
    44

    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.



    •   Alt19th October 2005, 09:50

      advertising

        
       

  6. #6
    Full Member level 2
    Points: 3,634, Level: 14
    H_u_n_t_e_r's Avatar
    Join Date
    Nov 2001
    Posts
    149
    Helped
    6 / 6
    Points
    3,634
    Level
    14

    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;



  7. #7
    Member level 5
    Points: 3,715, Level: 14
    Gorilla's Avatar
    Join Date
    Jan 2003
    Posts
    89
    Helped
    9 / 9
    Points
    3,715
    Level
    14

    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.



  8. #8
    Full Member level 2
    Points: 3,634, Level: 14
    H_u_n_t_e_r's Avatar
    Join Date
    Nov 2001
    Posts
    149
    Helped
    6 / 6
    Points
    3,634
    Level
    14

    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!



--[[ ]]--