Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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.

747 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

14 Experts available now in Live!

Get 1:1 Help Now