3D Spiral Image Rotation for MIX 09 Challenge Develop Silverlight on Eclipse : Eclipse4SL
Feb 17

I believe you will always make use of the scaling tool insider Flash or Blend. However, have you ever thought of achieving image scaling by coding?

That’s not an easy technique. You have to take care of the mouse position, image position, scale factor, cursor look, etc..

But don’t worry, here you could find a very simple demo for manipulating the size of the image. My sample is not intended to give you a complete/portable solution for Image Scaling. Instead, it provides you a basic idea how this is working.

Comparison

Flash implementation: 50 minutes

Silverlight implementation: 70 minutes (Implemented First)

Source codes

Flash

Silverlight

Silverlight: Create a custom property in XAML definition

If you open the Silverlight Source Code, you will find that the image is passed into the Image Manipulation Class directly in XAML. Here is part of the XAML code:

<custom:ImageManipulationScale VerticalAlignment=”CenterHorizontalAlignment=”Center“>
    <custom:ImageManipulationScale.Source>
        <Image Source=”shinedraw_logo.jpg” Width=”396” Height=”300“/>
   </custom:ImageManipulationScale.Source>
</custom:ImageManipulationScale>

It’s an important technique that everyone must know it. It definitely helps you to write a more professional control.

To start with, we have to define the property name and the property type. In the sample above, the property name is Source and the type is Image. Then, we are going to add some codings behind the Class ImageManipulationScale.

// C#
// create a custom property than can be exported to XAML
public static readonly DependencyProperty SourceProperty =
	DependencyProperty.Register(
	"Source", typeof(Image),
	typeof(ImageManipulationScale), null
	);

// define a public property with the name Source
public Image Source
{
	get { return (Image)GetValue(SourceProperty); }
	set
	{
		 SetValue(SourceProperty, value);
		// do whatever you want here
	}
}

That’s all! Pretty simple, right?

Shares and Enjoy~

Did you like this post?

Subscribe here:  

9 Responses to “Silverlight vs Flash: Image Manipulation - Scale”

  1. Silverlight Cream for February 17, 2009 -- #520 Says:

    [...] Silverlight vs Flash: Image Manipulation - Scale [...]

  2. Dave Says:

    Odd - the Silverlight version appears to perform much better but the scaling of the image seem to be better in Flash. The scaled down Silverlight image is a little pixelated.

  3. Flash vs Silverlight: Controlling UI Object Says:

    [...] If you want to add a resize functionality to the object, you may refer to my previous post Image Manipulation - Scale.  [...]

  4. Silverlight Says:

    Nice custom property!Good job! I’ve wrote an article about Silverlight too:

    Silverlight

    Regards,
    Mark

  5. Anas Marwan Says:

    Nice one…
    At the beginning i was a little bit fooled that silverlight renders the image better than flash, but when we want to compare the frame rate in this example we will find that silverlight has a default frame rate of (60 fps) while flash has only (24 fps) !, and that’s why it seems that silverlight renders the image better than flash, but if we put the two applications at the same level of frame rate, we will see that flash renders the image much more better than silverlight does !

  6. best web design Says:

    I must say, I could not agree with you in 100%, but it

  7. NewsPeeps Says:

    Silverlight vs Flash: Image Manipulation - Scale…

    Thank you for submitting this cool story - Trackback from NewsPeeps…

  8. struggler Says:

    I am a newbie trying to borrow this code (for Flash) and make it resize my object when clicked on. I am not having luck. Can you edit it for me so that I can apply the function to my own objects?
    Thanks

  9. syabac Says:

    thanks for sharing..
    keep moving forward..

Leave a Reply