I want to create a custom control for a image regarding the dynamic zoom functionality based on the selected part.It is just like the marquee zoom in the pdf 开发者_如何学Pythonreader.I used hierarchy of Stack panel,scroll viewer,canvas and then image.Can Anyone tell me how to zoom the selected rectangle part like the marquee zoom?
You should apply your rotate, zoom etc as a RenderTransform on the Image. You then need to ensure that the Image is contained within something that will clip the results, for example a Grid.
Actually Problem lies in the calculation of the zooming rate of the selected area.We have to fit the selected area to the size of the window.For that, we constantly increase the selected part by one percentage and every time checks with the size of the window.If it is greater the the window size then we stop increasing the selected area.
The logic as
double rate=0;
while (true)
{
if (selectImageHeight * (st.ScaleY + rate) < this.ActualHeight && selectImageWidth * (st.ScaleX + rate) < this.ActualWidth)
rate += 0.01;
else
break;
}
Zoom(rate);
Here o.o1 means one percent,this means window. Deep zoom is possible by using the code and scroll's ScrollToHorizontalOffset and ScrollToVerticalOffset values.
精彩评论