Solved

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

Posted on 1998-03-02
4
1,318 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now