Skip to main content

Answered Question Image size enlargeRSS Feed

(0)

skm.software@yahoo.com
skm.soft...

Member

Member

216 points

240 Posts

Image size enlarge

Hi

Can anyone give me a good example in which after click to
image its size enlarge with animation.

I have rotatin images in my project and I want
on the click of the images images size will enlarge.

Sachin Mukhija
"Please Mark as answer if answer is correct".

IanBlackburn
IanBlack...

Contributor

Contributor

2333 points

371 Posts

Answered Question

Re: Image size enlarge

Essentially what you need here is an animation to play on the image.  Since you mention "images" in the plural though I assume you want a single animation you can replay on any image.

There are two approaches to this:

  1. Create the animation in xaml (using Blend) on one Image and then change the target in code.  This is easier to do but means you can only play one animation at a time.
  2. Create the animation purely in code. 

Of course you can also have a combination of the two (so you could create the animation in blend, then create a copy of it in code and manipulate it)

Here's an example of the first approach.  This is the Xaml created by recording an animation in Blend against "Image1".   Notice that I have given the two DoubleAnimationUsingKeyFrames elements names (GrowImageScaleXAnimation and GrowImageScaleYAnimation) so that it is easy to change their properties in code later on:

		<Storyboard x:Name="GrowImage" AutoReverse="True">
			<DoubleAnimationUsingKeyFrames x:Name="GrowImageScaleXAnimation" BeginTime="00:00:00" Storyboard.TargetName="Image1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
				<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1.1" KeySpline="0.24,0.75,0.9,1"/>
			</DoubleAnimationUsingKeyFrames>
			<DoubleAnimationUsingKeyFrames x:Name="GrowImageScaleYAnimation" BeginTime="00:00:00" Storyboard.TargetName="Image1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
				<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1.1" KeySpline="0.24,0.75,0.9,1"/>
			</DoubleAnimationUsingKeyFrames>
		</Storyboard>
 

So if you have two images like this:

<Image x:Name="Image1" Width="100" Height="100" Source="Images/beta.jpg" MouseLeftButtonUp="Image_MouseLeftButtonUp" RenderTransformOrigin="0.5,0.5">
            <Image.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Image.RenderTransform>
        </Image>
        <Image x:Name="Image2" Width="100" Height="100" Source="Images/beta.jpg" MouseLeftButtonUp="Image_MouseLeftButtonUp"  RenderTransformOrigin="0.5,0.5">
            <Image.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Image.RenderTransform>
        </Image>

 You can write the following code to play the animation on either one:

        private void PlayXamlImageAnimation(string ImageName)
        {
            GrowImage.Stop();
            Storyboard.SetTargetName(GrowImageScaleXAnimation, ImageName);
            Storyboard.SetTargetName(GrowImageScaleYAnimation, ImageName);
            GrowImage.Begin();
        }

.

The purely code animation requires more work to build the animation, so rather than post it all here I have uploaded a sample to my skydrive here (this includes both the Xaml approach and the code one.

http://cid-fb8b852ef1ab0b35.skydrive.live.com/self.aspx/SampleCode/SilverlightImageResize.zip

(If this has answered your question, "Mark as Answer" - many thanks)

Cheers

Ian Blackburn
SilverlightForBusiness.net

skm.software@yahoo.com
skm.soft...

Member

Member

216 points

240 Posts

Re: Image size enlarge

 

Thanks Ian,

for a very good reply

But main problem is that in my project images are rotating. So i am getting difficulity to increase the size at runtime

my project is attached here

http://cid-b26803d805b4f34a.skydrive.live.com/self.aspx/Public/ImageRotation3D.zip

pls check it

Sachin Mukhija
"Please Mark as answer if answer is correct".

IanBlackburn
IanBlack...

Contributor

Contributor

2333 points

371 Posts

Re: Image size enlarge

Hi,

 

The problem with your project is that you are applying the animation listed above but your images are created silightly differently than mine, namely you do not have a TransformGroup - only a single ScaleTransform on each image.  So making the folllowing change to the posImage method in ImageRotation3D.Xaml.cs will stop that exception being thrown:

 

            TransformGroup group = new TransformGroup();
            group.Children.Add(scaleTransform);
            image.RenderTransform = group ;

 However the animation I created in the Xaml is not really appropiate for the images you are using, since it applies a 10% scale on the original size, and you are already scaling the images to create the rotation effect, so it will not really work.  This will probably be a case where using code to create the animation may be better because you can then take the current ScaleX and ScaleY values and increase them to get the effect you want.

Hope this helps.

(If this has answered your question, "Mark as Answer" - many thanks)

Cheers

Ian Blackburn
SilverlightForBusiness.net
  • Unanswered Question
  • Answered Question
  • Announcement