zooming a image Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
mohan
Experienced Solver
Experienced Solver
Posts: 61
Joined: Wed May 07, 2008 9:55 am

zooming a image

Post by mohan »

Hi all,
I selected a region of a image using a drag rectangle.I want to zoom that region of the image only and show it in the full window.Can somebody please elaborate the steps to be done for this implementation. Please help me..


Thanks,
Mohan
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

It will involve determining by wich factor to scale your image, then scale it, then adapt scrollbars to show the right area - which part of it causes problems to you?
mohan
Experienced Solver
Experienced Solver
Posts: 61
Joined: Wed May 07, 2008 9:55 am

Post by mohan »

I don't how to get the region(part of the image) selected by the drag rectangle.If I am able to get the data then I can zoom it.Is there any function to get the data from the selected rectangle.
User avatar
T-Rex
Moderator
Moderator
Posts: 1249
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Post by T-Rex »

I don't how to get the region(part of the image) selected by the drag rectangle.
I can give you a sample for non-public use if you want. PM me if you are interested.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

mohan wrote:I don't how to get the region(part of the image) selected by the drag rectangle.If I am able to get the data then I can zoom it.Is there any function to get the data from the selected rectangle.
This will involve catching mouse events.

The following wiki article shows how to catch mouse events on a panel : http://wiki.wxwidgets.org/Drawing_on_a_panel_with_a_DC

Once you catched a wxMouseEvent, you can get the mouse position on the panel : http://docs.wxwidgets.org/stable/wx_wxm ... eeventgetx

So catch mouse down, collect position, catch mouse up, collect new position. You've got the selected area
mohan
Experienced Solver
Experienced Solver
Posts: 61
Joined: Wed May 07, 2008 9:55 am

Post by mohan »

Thanks for our replies.I found some sample from this forum and managed to do it.I have another problem.After selecting the image and displaying in the same DC I get the drag rectangle displayed.I don't need the rectangle to get displayed.How can I do it?.Here is my code..

Code: Select all

//on mouse button up
void MyCanvas::OnLeftUp(wxMouseEvent& evt)
{
    //releases the mouse
	ReleaseMouse();
	//device context
	wxClientDC dc(this);
	dc.SetBackground(*wxWHITE_BRUSH);
	dc.Clear();
	//flags
	selected=true;
	leftclicked=false;
	//screen size
	wxSize screensize=this->GetClientSize();
	//zoom function
	dc.SetUserScale(2,2);
	//draws into the screen from memory
	dc.Blit(0,0,screensize.GetWidth(),screensize.GetHeight(),&dcMem,0,0);
   	evt.Skip();
}



void MyCanvas::OnMotion(wxMouseEvent& evt)
{
...
 //getting the part of the image and storing it in memory.
   wxBitmap bitmap(rect.GetWidth(),rect.GetHeight());
   dcMem.SelectObject(bitmap);
   dcMem.Blit(0, 0, rect.GetWidth(), rect.GetHeight(), &dc, rect.GetLeft(),rect.GetTop());
   dc.SetLogicalFunction(wxCOPY);
   savepoint=endpoint;
   evt.Skip();
}
EDIT by Auria : Please use code tags
van_user
Experienced Solver
Experienced Solver
Posts: 55
Joined: Wed Jun 11, 2008 9:28 pm
Location: UA

Post by van_user »

This is because you copy image from screen (as I see from post). Try to copy from source(when you need to evalute real coordinates) or crop region for cut draw rectangle.
Sorry for my English. I hope you understand idea.
Win XP (SP0), mingw, wx 2.9.0
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

I think the code is a little confusing, you are doing blitting and rendering from two different places

Now this is a design decision so it's subjective and others would do different from me, but here's what I'd do : separate data and view. Don't mix up collecting data and rendering them. Create variables/classes to keep the information about the display. In mouse events, update the data, then call paint events as needed. In the paint event, read the data and display the image accordingly.

I myself wouldn't draw the image to the screen, then get it back from the screen, then draw it again, etc. I would always start from the original wxImage/wxBitmap object (unless it's very big, that is)
mohan
Experienced Solver
Experienced Solver
Posts: 61
Joined: Wed May 07, 2008 9:55 am

Post by mohan »

I understood my problem.The rectangle gets displayed because I am getting the image from the screen.Thanks for your replies.Can you please help me how to get the region I selected using selection rectangle?.Will GetClippingRegion() function do that?
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

mohan wrote:I understood my problem.The rectangle gets displayed because I am getting the image from the screen.Thanks for your replies.Can you please help me how to get the region I selected using selection rectangle?.Will GetClippingRegion() function do that?
The docs website is down ATM so i can't check what this method does, but IIRC it's a wxDC method about limiting drawing to a certain area. That won't do it.

Try to make your way through mouse events only - there is no DCs or drawing involved there (remember, the sepaeration between view and data i mentionned earlier)

In mouse events, you can catch the location of mouse. This is how i would get the location of the selected rectangle.

Code: Select all


// pseudo code, adapt as needed
void MyPane::OnMouseDown(wxMouseEvent& e)
{
  selection_x_start = e.GetX();
  selection_y_start = e.GetY();
  selection_x_end = -1;
  selection_y_end = -1;
}
void MyPane::OnMouseMoved(wxMouseEvent& e)
{
  if(e.Dragging())
  {
    selection_x_end = e.GetX();
    selection_y_end = e.GetY();
  }
}
void MyPane::OnMouseMoved(wxMouseEvent& e)
{
    if(selection_x_end != -1 && selection_y_end != -1)
    {
       zoom = ... ;
/* calculate good zoom from coords or whatever depending on how your drawing method works ... */
       Refresh();
    }
}
Post Reply