Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 1998-03-02
4
Medium Priority
?
1,510 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 300 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

824 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