Solved

Draw an area over a Bitmap in C++ Builder?

Posted on 1998-03-02
4
1,391 Views
Last Modified: 2012-05-05
i'm trying to write a program that one of its task is let the user to select an area over a bitmap.
The area must be select with a rectangle over this image. The user must press the mouse button,
to select the origin point, and then must move the mouse to the final point, and release the button,
to finish the selection. A rectangle must be painted while the user is moving the mouse from the origin
point to the final point, showing the area selected in each moment.

I've tried to do this with a canvas in a TImage object for the bitmap  but i can't clean every rectangle
that i paint while the mouse is moving to the final point.

      How can i write this program?
      what C++ Builder objects must i use?
0
Comment
Question by:ineila
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
inter earned 100 total points
ID: 1182926
Dear ineila,

Do the following:(I am sure you do it partialy)

1 - Declare int OriginX, OriginY, OldX, OldY; BOOL drawing = false
2 - On MouseDown event of the TImage Set OriginX = x, OriginY = y
3 - On MouseMove event
    if (drawing) {
      Image1->Picture->Bitmap->Canvas->Rectangle(OrigingX,OriginY,OldX,OldY);
      OldX = x; OldY = y;
      Image1->Picture->Bitmap->Canvas->Rectangle(OrigingX,OriginY,OldX,OldY);
    } else {
      Image1->Picture->Bitmap->Canvas->Mode = pmXor; //this is the trick!!!!
      OriginX = x;OriginY = y;
      OldX = x; OldY = y;
      Image1->Picture->Bitmap->Canvas->Rectangle(OrigingX,OriginY,OldX,OldY);
      drawing = TRUE;
    }
4 - On MouseUp event
     if (drawing) {
      Image1->Picture->Bitmap->Canvas->Mode = pmCopy;
      drawing = FALSE;
     }

the idea is that when you want such a restoration, the pmXor mode help. The drawing you have made combines the colors with xor operation. If you draw the same thing second time the image became unaffected.

Need more, as more please
Igor


0
 
LVL 5

Expert Comment

by:inter
ID: 1182927
Excuse me On MouseDown

  if (drawing) {
      Image1->Picture->Bitmap->Canvas->Mode = pmXor; //this is the trick!!!!
      OriginX = x;OriginY = y;
      OldX = x; OldY = y;
      Image1->Picture->Bitmap->Canvas->Rectangle(OrigingX,OriginY,OldX,OldY);
      drawing = TRUE;
  }

and DELETE the OnMouseMove ELSE part

Igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1182928
Awfully sorry,

In previous comment If (drawing) be if (!drawing)..

igor
0
 

Author Comment

by:ineila
ID: 1182929
The answer its good.

I have found another way, this is creating a TShape object over the Timage.
The algorithm is similar, when you press the mouse button i select the
origin position, and when i move the mouse i select the final position. When
mouse button is released the shape takes its final size.


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question