Morphing from an image to a shape in Silverlight 3 - silverlight

I have a requirement to morph from an image (png) to a shape (polygon) in Silverlight 3 as an effect, but of course there is no built in transition or method to do this.
At the moment the best I have is fade one out and the other in, but can anyone suggest a decent alternative that may work or look better?
Regards
Moo

In Blend:
Create a rectangle. Set stroke to No Brush and Fill to Tile Brush.
For the ImageBrush of the Tile Brush, select your image.
In the object browser, select the rectangle, right click > Path > Convert to Path.
Use the pen tool to add some points to the path.
Add a storyboard.
Add a keyframe at 1 second. Blend will go into record mode
Use the direct selection tool to move the points into the polygon shape you want. Test out your animation.
At this point, the image morphs into a shape, but the image is still there. If you need to remove the image as well as morph it:
In your storyboard, at the keyframe at 1 second, change the opacity to 0.
Create a copy of the rectangle, but make sure fill is set to No Brush and Stroke is set to a color and width. Set the opacity to 0.
Add points, and mimic the animation you just set up for the image's rectangle.
Add a keyframe at 1 second for this element. In record mode, change the opacity to 100%.
The end result will be both paths morphing, the one with the image fading out while the one with no fill fading in.

I'm not a silverlight programmer, and don't know the details of what you want to do, so this is just a shot in the dark, but... if the shape you want the image to morph to is always going to have the same initial visual appearance (or some limited set of appearances) you might try morphing from the original image to an image of that shape, and then swapping the image that's the morph target for the geometry once you're done the morph. Course whether that would work or not is very dependent on the details of what you're doing. Sorry if you've already considered that and ruled it out.

You could possibly morph the image brush to the path of the shape by using an appropriate projection matrix. Or render a shape using the image brush and then morph that shape to the target shape, i.e. go from a rectangle to the target shape but using the image brush as the shape background. You may need to still warp the image brush somehow though.
An example of rendering a warped image is here in Charles Petzold's blog.

Related

Image glimmer or sparkle animation

I've been searching for awhile, but haven't been able to find anything. I'd like to be able to add kind of a glimmer or sparkly animation on an image element in wpf.
Essentially the effect here I'm after here is the same that you get with trading cards that are "foil's".
I'd like to have an image, and then be able to add this animation to it at will. I'm thinking maybe some kind of user control, or template possibly. Hopefully generic enough that I can just toss an image at it and it will just overlay the image and run.
Any ideas?
A simple construction that easily can be turned into a control is by nesting the image in a Grid and adding a second Grid (on top) as a sibling.
De second grid can be given a linear gradient brush that is primarily transparent but does contain a white glimmer.
This brush can be animated; you could move it and change the opacity of the grid/brush.
This way you do not change the image.

How to do Free hand Image Cropping in WPF?

all
I m developing on Medical Image Processing software, I wont crop image on mouse event, means when we drag mouse cursor and move over the image in any shape, the selected portion of image should be cropped. and that will paste in same image. is it Possible in WPF or Silverlight?
Check out the Clip property. You can specify a path in this property that is used to clip the parent object. Set Clip on your Image control to clip the image.
For design time clipping, your best bet is to use Blend (download a trial here if you don't have it) to draw a free hand path. Right click on the path and select Path->Make Clipping Path. In the next dialog, select the image that you want to clip.
EDIT: It sounds like you want to use runtime clipping/cropping, so you will want to generate the clip path using the points gathered from the mouse events. Create a collection of these points and then generate a path from them (linear lines probably... I don't know how you would generate appropriate curves unless you wrote a complex algorithm). Set this path to the Clip property after the fact.
/EDIT
You can add a transparent layer on top of the control and add an InkCanvas.
Then allow the user to draw a stroke (freehand) and turn the stroke into a Geometry by using GetGeometry use the geometry in the Clip property of the control to be clipped.

What is the best way to copy / clone brushes?

Before drawing a shape on a canvas I have a preview that displays how the shape will look. I can adjust the opacity and then draw the shape. I may then wish to draw a second shape with a different opacity. My problem is that altering the opacity of the preview also alters the opacity of the shape that I have already drawn.
This has led me to believe that I need to create a copy of the brush used for the preview each time before drawing the shape.
There are various different brushes and for example, the gradient brushes require making a copy of the not just the gradient stop collection, but a new gradient stop for each gradient stop in the to-be-copied collection.
Am I down the right track here or should I be doing something else? Should I be copying or cloning? Would an extension method be the best way to go? Thoughts please.
What you need is cloning, it would be easy in wpf with XamlWriter/Reader, unfortunately you cannot do it in Silverlight. An extension method on Brush that makes a deep copy would work fine in your case though. You will have to handle the different brush type separately but it should not be an issue as there aren't that many.

Change Alpha Blend Mode in WPF?

The System.Drawing.Graphics class has a property CompositionMode with two options: SourceOver (which, based on the alpha component, blends whatever is drawn with the background already existing) or SourceCopy which simply overwrites the background with whatever is being drawn.
Does something similar exist in WPF?
In WPF when i draw a PolyLine for example on top of another the new PolyLine always alphablends with the background. I think that is independent of the container being used. I am using a Canvas but could not find a blend mode property anywhere. What I want to do is what the SourceCopy compositionmode mentioned above does. I.e. the new PolyLine should simply overwrite whatever is already on the Canvas.
Is there a simple way to do that, short of using pixel shaders (which - as far as I understand - wouldn't work anyways because I don't have access to the Canvas backbuffer).
I am not stuck with a Canvas and would be happy to use any container that supports overwrite mode.
I currently have a solution based on a WriteableBitmap for which I obtain a System.Drawing.Graphics context and then manipulate the CompositionMode. It works but since my window is fullscreen that solution has serious performance impacts.
Clarification and example:
The WPF window is fully transparent and so is the Canvas (back ground color(0,0,0,0)). Now I draw a PolyLine with a Color.FromArgb(128,128,0,0). I now have a semi-transparent red polyline. Next I draw the same PolyLine with Color.FromArgb(0,0,0,0). The result is the same as before because of the alpha blending taking place. What I want, however, is that the red polyline is erased with the second polyline (which is exactly what the SourceCopy mode in the Graphics class does.
I think all you need to do is make sure that the brushes used to fill/stroke the PolyLine have fully opaque alpha values (i.e. 255). Then the background shouldn't be blended into it.
You could apply a Clipping Mask, this way you can provide the path to clip over the elements that are below it, but it might be tough to maintain after a lot elements are required to be clipped...

WPF VisualBrush with mixed aspect ratio

We are using the Mindfusion WPF Diagramming Component. I require a Visualbrush which must be able to be used in a third-party component for diagramming.
We have horizontally-stretching lanes on the diagramming canvas. We must define a background color for this lane, and some text on the top-left corner, to be repeated on the x-axis. The text must remain the same size while the rest of the lane is filled with color when the lane is re-sized.
Unfortunately, the only thing we can do is provide a Visualbrush to the diagramming component, which is then set as background for the lane. It seems impossible to work with this restriction because I am unable to define a text with fixed size, repeating on the x-axis, while also having a color brush stretching, all within a single Visualbrush. How can this be done?

Resources