Xna custom VertexElementFormat and VertexElementUsage? - c#

I'm a little confused and not sure how or if this is possible, but is it possible to create custom ones? VertexElementFormat doesn't contain the type I want to use which is byte3 and I have no idea how I could add that to it :/.

No, you can't. For your purposes, you can probably use Byte4 or Color.
These settings tell the GPU how to decode the data you send it and place it in shader registers. They are not extensible.
Note that you can have more than one Position or more than one Color (for examples) by setting the UsageIndex in your VertexElement.

Related

System.Drawing.Drawing2D.GraphicsPath.PathData documentation/examples

I want to write a converter from GraphicsPath to a different format.
MSDN seems very terse on this topic and doesn't help to create a full picture - I can't be sure I can handle all point types correctly.
PathPointType Enum,
GraphicsPath.PathTypes Property
- both repeat approximately the same description, except it doesn't give the full picture to someone who are not familiar already with what it supposed to mean.
I can dump some time into reversing it from hand-crafted examples, but I can't estimate and justify the time for that and I'm not sure I can cover all cases.
Is there an article/example that is targeted for custom rendering of GraphicsPath rather than for consumer code and also goes into greater detail?

Powerpoint "Save As Picture" from C# Microsoft.Office.Interop.PowerPoint

My question is pretty similar to this one and I'm afraid the answer is the same... I want to save all the shapes/images on a slide as a single png (or jpeg). Programmatically, I get as far as
slide.Shapes.SelectAll();
but don't see a way to save as image. Is this possible? If not, any other suggestions, hopfully w/ examples? (not VBA - I need to automate the whole conversion)
There was a reference to OpenXML in the other post, but I'm not even sure how to pull that in.
I don't know how you'd do this in C# but I'd guess that you'd make use of the same methods as you would with VBA, where you can do:
Activewindow.Selection.ShapeRange.Export( "c:\temp\delete-me.jpg",ppShapeFormatJPG)
ppShapeFormatJPG is a PowerPoint constant, a VBA Long = 1; IIRC that'd be an Integer in C#.
The method also can take two more optional parameters, scalewidth and scaleheight, which govern the width and height of the exported image in undocumented ways. By default, no parms supplied, I get exports at 72 dpi. Larger numbers result in higher pixel count exports but distorted proportions. I'm sure there's some strange logic to it, but it escapes me; all hints welcome!
There's a third optional parm, ExportMode. In my tests, it makes no difference whether you supply it or not, and if you do, which of the available values you choose.

Approval Tests Image comparison with mask

Is it possible to compare two images with a mask for area's that do not need to be compared.
I managed to get it working with a basic file comparison
[UseReporter(typeof(BeyondCompareReporter))]
public void ThenThePageShouldMatchTheApprovedVersion()
{
SaveScreenshot("page1");
Approvals.VerifyFile(#"C:\page1.png");
}
But i would like to create a mask of the area's i expect to change. Is this possible with ApprovalTests or will i need to modify the screenshot and manually apply the mask before comparing with the approved file. Or is it possible to write your own validators?
It's not possible to mask the area so the comparer will not compare them.
However, it is very easy to actually mask the area (ie, place a black square over the area before you call Verify)
Alternatively, you can usually mock out the variable that is changing.
Details on Comparer:
ApprovalsFileComparer is a very stupid comparer. It knows nothing about file formats and has no idea of what an image is. It simply compares byte to byte. This simplicity allows it to work everywhere, but removes the ability to be smart about stuff. This is usually not an issue as the reporters are very very smart. Able to render and compare and do subtractive diffs and the like.
Happy Testing!

Is there a way to make XAML / C# StringFormat show whole dollars for larger amounts but cents for smaller amounts?

In XAML, it is easy enough to use StringFormat='$#,0;$-#,0;Nil' to make a bound integer variable display as a nicely formatted dollar amount. e.g., 1024 would come out as '$1,024'.
I have a need to deal with numbers ranging from a few cents up to a few hundred dollars - so 0.45 should display as '$0.45', but anything greater than some threshold (1? 9.99?) should display as a whole dollar amount. E.g. 12.73 should display as '$13'.
Before I go ahead and roll some moderately messy and specific code, does anyone have a nice clever way to do this? Ideally, it would all be in the StringFormat :)
I can't see how all this logic can be put in the StringFormat.
I think the cleanest way is an IValueConverter implementation. You can use a converter parameter to set the threshold, so that the converter can be reused and does not have a hard-coded value.
Unless you are using two-way binding, and if you are implementing MVVM, it is probably preferable to have a string variable in the view-model that returns the display value based on the integer value.
Don't be afraid of creating a Value Converter for this specific scenario.
If there is a business need for this type of formatting then it will quite likely be reused later anyway and making it a Value Converter makes it easier to reuse and test.
Jay's suggestion is probably as clean as it gets as your requirement will need to use logic for the formatting threshold.
try
StringFormat='$ 0.##;#,$ #.##'

How to implement a band-pass filter in c# / Silverlight

How would I go about implementing a band-pass filter in c#? I'm using a custom MediaStreamSource in Silverlight and am using additive synthesis to produce sound. My audio stream is a continuous stream of int16 shorts:
//over-simplified example:
short sample = oscillator.GetNextSample();
memoryStream.WriteByte((byte)(sample & 0xFF));
memoryStream.WriteByte((byte)(sample >> 8));
...where "sample" is a function of a sine calculation (or some other complex combination of waveforms) ranging from short.MinValue to short.MaxValue.
I have no idea where to start with a band-pass filter. How would I go about implementing it?
Ah, this is what I'm looking for:
Low pass filter software?
I haven't tried it yet, but that is the raw calculation example I was hoping to find. It looks like I'll need to revise that code to work with Int16's instead of doubles, and it also looks like I have a lot of dirty work ahead of me for defining the particular constants/coefficients I'll need, but it should get me started in the right direction.
See the answers to this question, in particular you might find Jacob's answer useful.
puhh this is math , isnĀ“t it ;-)
So I guess its System.Math
and read this free book

Categories