Animate a sprite by using two images - c#

I would have thought this was a common desire, but I'll be damned if I can find this.
I simply want to Animate an image by swapping two images back and forth. I tried StoryBoard, but apparently you can't change the source in a storyboard. The only answer I can come up with is a Timer, which I don't think is the best way.
Edit: How do I animate image content in WPF? Came up in the "Similiar Questions" window. And while this will do what I want, it is "hackish" as the OP of it says, and it only swaps two images, what if I wanted a whole sequence of 10 or 20 or 100.

I found another post here on SO whose answer sounds like it could solve your problem: Change an image during animation using storyboard
The problem with this approach is that it also doesn't satify your request for supporting an arbitrary number of images.
I was going to propose a different method that involves databinding the Image Source to the image path, and then in code behind simply changing the path, but I haven't gotten it to work yet.
Here's an article that seems to have an elegant way to handle your requirements: http://www.codeproject.com/Articles/364529/Animation-using-Storyboards-in-WPF
Hopefully that will work for you.

Related

How to create custom shaped Buttons in WPF?

(Before this gets marked as a duplicate, I'd like to say that I've tried the answers on other posts, but they don't seem to work for my specific issue.)
I'm creating a sort of "map game", where there's a map split into multiple areas. Currently, this is what I have:
It works, but it's not pretty. I want to make the buttons (currently they're the Rectangle control, but I can change that easily) the right shape.
I tried making a path in Inkscape, which gave me this SVG path:
m 283.60033,267.22114 11.61675,32.57742 14.14214,-8.33376 10.35406,-1.01015 11.61676,-5.3033 10.6066,-5.05077 0,-16.66751 -34.85027,-3.78808 -8.08122,2.77792 -14.64721,0.75762 z
However, when I tried to make a Button (and later Polygon) use the path, it didn't work and instead made a completely different shape.
The Buttons need to have a background color that can change during runtime, so a PictureBox won't work.
Is there a reason why the Path didn't work? Or maybe there is a much easier method?
EDIT: Here is the code I used for the Polygon
<Polygon Fill="Blue" Points="283.60033,267.22114 11.61675,32.57742 14.14214,-8.33376 10.35406,-1.01015 11.61676,-5.3033 10.6066,-5.05077 0,-16.66751 -34.85027,-3.78808 -8.08122,2.77792 -14.64721,0.75762" Margin="248,102,956,22" RenderTransformOrigin="0.5,0.5" Grid.ColumnSpan="2"/>
And here is the result, which is the same shape I got when I tried changing the shape of a Button (unfortunately I deleted the code for that):
Here is what it should look like (path drawn in Inkscape):
I figured it out and it was actually pretty easy! I actually didn't need Inkscape at all.
I imported the map image into Blend, and I traced the area with the Pen tool and made it into a Path, which I copied back into Visual Studio.
Example:
Are you sure you didn't get mixed up with which part you picked out the xaml inkscape produced?
Because that's roughly the top right part of the iberian peninsular. Like your drawn map. Roughly anyhow. That's just a polygon - with hard edges. Meaning however you produced it, you didn't trace the curvy/rough edges of what you're showing us.
Also.
If you look at the data that's in it.
See where it starts?
m 283.60033,267.22114
Those are x,y co-ordinates.
268px left, 267px down
From the top left corner of whatever container you put it in.
Is that going to work for you?

Redraw Image every ~5ms

I have a Picturebox with...content approximately 2000x1080 pixel (yes, this makes sense for me)
Now I need to get the old content, replace it 1 pixel down and fill the empty line on the top with new data.
BUT I have to do this in a very short time ~5ms maybe a little bit more.
I get the trigger and the new data to do so.
So now the question is:
What is the fastest and cleanest way to do this?
Maybe I need to buffer the new data and write them in a more "human" time!?
You didn't mention what kind of app it is... I'm more of a web developer, but in jquery, the trick to this is to load all images with zero visibility, and then use logic to determine which to display; I would think that even if this isn't web based, you could use a similar approach... just line them all up on the screen, set the left most to be visible, and then every 5ms, make the next visible... if you were constantly adding images, just make sure you're loading them earlier, maybe during the 5ms between switches?

High performance plot control in WPF

I am doing some work for which I need to develop a control, it should be a simple graph that shows several points and two edges.
My problem is that I need to show up to 16k points, with an update rate of 30 Hz. Has anyone done something similar?, and has any advice?.
For example whether to inherit from FrameworkElement or Control (ItemsControl in this case). If the control inherits from FrameworkElememt it may have a better performance drawing the points in the OnRender method but I would miss the Templating feature that comes from inheriting from Control.
Or does there exist another control that can do this out there?
Thanks in advance for your time.
I ended up using InteropBitmap, it is the fatest bitmap rendering class from WPF.
It allows you to map the image that you want to paint (in memory) and then reder it as a Image. This was perfect as i needed to plot points on the screen.
I got great performance (almost 50Hz for 20k points), i also use PLINQ to update the points in memory.
check this article for more details...
Try and read about ZoomableCanvas. I believe it can solve your problem. You can render all the points as small rectangles/ellipses inside the ZoomableCanvas.

Image OCR - Filtering unwanted data

Basically I'm reading vehicle license plates using tessract OCR, however despite being able to emphasise text easily enough via changing contrast, reducing noise an so on, some 'parts' of the vehicle remain on the image which does cause the OCR to throw bad results.
For example take:
I can change this easily enough, such as:
I'm looking to eliminate the edges off each plate, here's another example:
I could remove the edges using pixel manipulation algorithm, however I don't feel it's the right method, and would cause quite a lot of problems.
I've been using the following application to test various methods such as morphology and eliminating the unwanted data, so far I haven't been successful.
http://www.codeproject.com/KB/GDI-plus/Image_Processing_Lab.aspx
However someone with knowledge of this could use the application on the article above to achieve want I'm trying, so feel free to give it a try.
Thanks
Please try to use stroke width transformation concept.
This concept use to segment text from natural images.....
I already did such an algorithm. I just can say that it works great. The secret is, that you need to know that the light is coming just from one side perhaps. You cannot set the image to "black/white" just by using ONE threshold.
Detect the average luminance of parts of the image and use this luminance calculation to set the threshold for each region.
For example, if the left top is lighter, you need a lower threshold to make these parts not to bright. And if the bottom right has low light, you need to set the threshold higher to receive all existing light information.
Then, you need just to drive into the image from each side by using the method:
IsPixelAboveThreshold ?
If it is below, you are on the border, if it is above, you can say you are on the middle of the image with more brightness.
Regards

wpf custom control: audiowaveform rectangle with selection slider

I'm working on a c# wpf app in which I want to do something with audio. the irrklang audio library provides me with a pcm decoded 16 bit byte array.
I want to create a timeline control which shows the waveform along the timeline with an overlaying rectangle which the user can drag and click/drag the left and right side to increase or decrease the selection.
It is used to the trim the audio track. I would like the selected min and max to be databindable, the minimum and maximum value of the total track to be bindable.
To clarify here is an image mockup:
I'm not asking for a complete control but tips and suggestions on how to tackle this are more than welcome. Perhaps solutions like this already exist but so far I haven't been able to find it.
I think I need to tackle: the control (zooming, panning and changing the selection) and drawing the waveform in the control
Thanks in advance,
I think you should check out this codeplex project
http://wpfsvl.codeplex.com/
Refer to Audio WaveForm Drawing Using WPF.
Something based upon WaveFileTrimmerControl.xaml would be useful, it uses related controls PolygonWaveFormControl.xaml & RangeSelectionControl.xaml (links are to the XAML but refer to the CS also). In any case it'd be a good starting point for building a control that exactly meets what you want.
You could override the render method and use primitives which will give possibly better performance; but like anything related to performance I'd try the above approach first which is almost certainly good enough.

Categories