zooming a image Topic is solved
zooming a image
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
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
This will involve catching mouse events.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.
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
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..
EDIT by Auria : Please use code tags
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();
}
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)
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)
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.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?
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();
}
}