Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Change bitmap on VCL TImage component

Denny_BDenny_B Member Posts: 70
Hi all C++ Builder programmers,
could you please help me to change a bitmap image on a TImage VCL component (Builder C++ 6 Pro). I tried to use GetBitmap() message from TImageList component: MyImages->GetImage(0, MyImage->Picture->Bitmap). The bitmaps I want to swap are stored in TImageList (MyImages) component. The GetBitmap message is called on mouse click event and returns true, but the bitmap does not change.
Thank you for your help in advance,
Denny_B

Comments

  • bilderbikkelbilderbikkel Member Posts: 754
    On
    http://www.codepedia.com/1/CppBuilderLowLevelGraphics
    it is described how to do fast low-level graphics on TBitmaps (using Draw and ScanLine).

    It is more common to have all images possible in an TImageList, which are created in the 'Loading program, please wait' screen.

    : I want to swap are stored in TImageList (MyImages) component.
    I can help you with this problem, if you post code. Do not forget to use the [leftbr]code] tag!

    See ya,
    bilderbikkel

  • Denny_BDenny_B Member Posts: 70
    : I can help you with this problem, if you post code. Do not forget to use the [leftbr]code] tag!
    :
    : See ya,
    : bilderbikkel
    :
    Thanks bilderbikkel for your prompt reply.

    The code is very simple,
    I have a TImage (myImage) and a TImageList (myImages) VCL components on a form. The myImages list stores bitmap images I want to swap on mouse click. Their indeces are 0,1. On mouse click event I have the following code:
    [code]
    bool bPickXZ; //defined in the header file
    int ind = 0;

    bPickXZ = !bPickXZ;
    if( bPickXZ )
    ind = 0;
    else
    ind = 1;

    myImages->GetBitmap(ind, myImage->Picture->Bitmap);
    [/code]
    Although the function GetBitmap() returns true value, the image is not changed. No warning or error either.

    Thank you for your time and help,
    Denny_B






  • bilderbikkelbilderbikkel Member Posts: 754
    [b][red]This message was edited by bilderbikkel at 2005-12-1 6:14:24[/red][/b][hr]
    (sorry for the late reply, the messageboard was broken)

    Getting the pointer to the TBitmap does not cause C++ Builder to redraw the TImage. Therefore add the simple line below:

    : [code]
    : bool bPickXZ; //defined in the header file
    : int ind = 0;
    :
    : bPickXZ = !bPickXZ;
    : if( bPickXZ )
    : ind = 0;
    : else
    : ind = 1;
    :
    : myImages->GetBitmap(ind, myImage->Picture->Bitmap);
    [red] myImage->Refresh(); [/red]
    : [/code]

    Have fun with it,



  • Denny_BDenny_B Member Posts: 70
    : [b][red]This message was edited by bilderbikkel at 2005-12-1 6:14:24[/red][/b][hr]
    : (sorry for the late reply, the messageboard was broken)
    :
    : Getting the pointer to the TBitmap does not cause C++ Builder to redraw the TImage. Therefore add the simple line below:
    :
    : : [code]
    : : bool bPickXZ; //defined in the header file
    : : int ind = 0;
    : :
    : : bPickXZ = !bPickXZ;
    : : if( bPickXZ )
    : : ind = 0;
    : : else
    : : ind = 1;
    : :
    : : myImages->GetBitmap(ind, myImage->Picture->Bitmap);
    : [red] myImage->Refresh(); [/red]
    : : [/code]
    :
    : Have fun with it,
    :
    Thanks bilderbikkel for your reply,
    but I am sorry it does not work (at least on my system - Windows XP Pro, Builder C++ 6 Pro, leagal version). I actually had the Refresh() message in my code before, but for the whole Form (I know its inefficient). I tried also Invalidate(), but no progress. I think this VCL component does not work. I will try some other method how to display a bitmap on the form. I'll post it if I get it.
    Cheers,
    Denny_B
  • bilderbikkelbilderbikkel Member Posts: 754
    Hi Denny_B,

    I got it to work, and put the code on CodePedia:
    http://www.codepedia.com/1/CppBuilderTImageList

    I think the problem was that the TImage was not properly initialized. If you want it to be a bitmap (like I always want it to be), you either load a bitmap in design time or load a bitmap from file. I always use a 1x1 bitmap created in Paint (called '1x1.bmp').

    Have fun with it,
    bilderbikkel

  • Denny_BDenny_B Member Posts: 70
    : Hi Denny_B,
    :
    : I got it to work, and put the code on CodePedia:
    : http://www.codepedia.com/1/CppBuilderTImageList
    :
    : I think the problem was that the TImage was not properly initialized. If you want it to be a bitmap (like I always want it to be), you either load a bitmap in design time or load a bitmap from file. I always use a 1x1 bitmap created in Paint (called '1x1.bmp').
    :
    : Have fun with it,
    : bilderbikkel

    Hi bilderbikkel,
    thanks for your reply, my problem is partly solved - I can change the bitmap image at runtime with TBitmap::LoadFromFile() and TImage::Canvas::Draw() message (Thus I do not need the TImageList component). However this is rather inconvenient for shipping purposes - I have to ship the bitmap files along with the application. But it is a progress.
    What I found with the previous method (TImageList::GetBitmap()) was, that the bitmap was drawn always on top of each other. The previous bitmap in the TImage component was not deleted. This is why it seems that the function does not work - it works, but the result is not correct.
    Thanks for your help and your effort with codepedia.
    Denny_B

Sign In or Register to comment.