Page 1 of 1

zooming a image

Posted: Sun Jul 13, 2008 6:25 am
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

Posted: Sun Jul 13, 2008 7:41 pm
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?

Posted: Mon Jul 14, 2008 4:07 am
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.

Posted: Mon Jul 14, 2008 10:44 am
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.

Posted: Mon Jul 14, 2008 11:56 pm
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

Posted: Tue Jul 15, 2008 4:59 am
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

Posted: Tue Jul 15, 2008 10:18 am
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.

Posted: Wed Jul 16, 2008 12:05 am
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)

Posted: Wed Jul 16, 2008 6:27 am
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?

Posted: Wed Jul 16, 2008 11:48 pm
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();
    }
}