Solved

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

Posted on 1998-03-02
4
1,454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

630 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