Click here to Skip to main content
15,888,263 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developed the sample application to manipulate the image.
When I am dragging/zooming the image more, the image going out of the screen.

How to I limit that?

Thanks in advance..
Posted
Comments
Jaganathan Bantheswaran 24-Apr-12 2:22am    
the image going out of the screen.... means what ?
kamaraj sp 24-Apr-12 5:08am    
If I zoom out the image more, the image is not visible its looking like a dot and I couldn't zoom again. If I drag the image to corner of the screen, the image is going out of screen.
El_Codero 24-Apr-12 18:50pm    
I think it's nearly impossible to help without code. Regards
kamaraj sp 30-Apr-12 2:43am    
public sealed partial class BlankPage : Page
{
private TransformGroup _transformGroup;
private TranslateTransform _translate;
private ScaleTransform _scale;
private RotateTransform _rotate;
private bool forceManipulationsToEnd;


public BlankPage()
{
this.InitializeComponent();

forceManipulationsToEnd = false;
Img1.ManipulationStarting += new ManipulationStartingEventHandler(Img1_ManipulationStarting);
Img1.ManipulationStarted += new ManipulationStartedEventHandler(Img1_ManipulationStarted);
Img1.ManipulationDelta += new ManipulationDeltaEventHandler(Img1_ManipulationDelta);
Img1.ManipulationCompleted += new ManipulationCompletedEventHandler(Img1_ManipulationCompleted);
InitManipulationTransforms();
}

///
/// Invoked when this page is about to be displayed in a Frame.
///

/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}

private void InitManipulationTransforms()
{
_translate = new TranslateTransform()
{
X = 0,
Y = 0
};

_scale = new ScaleTransform()
{
ScaleX = 1,
ScaleY = 1,
CenterX = Img1.ActualWidth / 2,
CenterY = Img1.ActualHeight / 2
};

_rotate = new RotateTransform()
{
Angle = 0,
CenterX = Img1.ActualWidth / 2,
CenterY = Img1.ActualHeight / 2
};

_transformGroup = new TransformGroup();
((IList<Transform>)_transformGroup.Children).Add(_rotate);
((IList<Transform>)_transformGroup.Children).Add(_scale);
((IList<Transform>)_transformGroup.Children).Add(_translate);

Img1.RenderTransform = _transformGroup;
}

void Img1_ManipulationStarting(object sender, ManipulationStartingRoutedEventArgs e)
{
forceManipulationsToEnd = false;
e.Handled = true;
}

void Img1_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
e.Handled = true;
}

void Img1_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{

if (forceManipulationsToEnd)
{
e.Complete();
return;
}

_rotate.Angle += (e.Delta.Rotation * 180 / Math.PI);
_scale.ScaleX = _scale.ScaleY *= e.Delta.Scale;
_scale.CenterX = Img1.ActualWidth / 2;
_scale.CenterY = Img1.ActualHeight / 2;
_translate.X += e.Delta.Translation.X;
_translate.Y += e.Delta.Translation.Y;

e.Handled = true;

}

void Img1_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
e.Handled = true;
}

async private void BtnLoad_Click(object sender, RoutedEventArgs e)
{

FileOpenPicker imagePicker = new FileOpenPicker
{
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
FileTypeFilter = { ".jpg", ".png", ".bmp", ".gif", ".tif" }
};

StorageFile imageFile = await imagePicker.PickSingleFileAsync();

if (imageFile != null)
{
//this.scenarioId = ScenarioId.Image;
IRandomAccessStream displayStream = await imageFile.OpenAsync(FileA
S p k 521 16-Jun-12 4:00am    
hi,
i have tried this code in my capture metro application to drag the captured image.. but it goes out of screen.. please tell your suggestions..

Regards,
Suku

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900