I have raw data in a custom image format (canot be changed) that is stored in column major order (after some binary header data). I read the file into a Byte[] called “imageDataBytes”.
int XSize = 1280; // Really the height of the image
int YSize = 2048; // Really the width of the image
WriteableBitMap myImage = new WritableBitmap(XSize, YSize, 96, 96, PixelFormats.Gray16, null)
System.Windows.Int32Rect rect = new System.Windows.Int32Rect(0, 0, XSize , YSize);
myImage.WritePixels(rect, customImage.imageDataBytes, stride, customImage.imageOffset);
Now, I show this in XAML with
<Image Grid.Column="0" Grid.Row="1" Cursor="Cursor1.cur"Source="{Binding myImage}" Stretch="None"/>
I need to get the image rotated (to correct for the column major order in the bytestream but I can’t find array transformations for the Byte[] similar to IPPs in C# (and I don’t have IPP available here). And The rotation of the image from xaml moves the image all over the place (rather than rotating around the center).
<Image ... // From above>
<Image.RenderTransform>
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="-90"/>
</Image.RenderTransform>
</Image>
What can I do? Am I missing the transforms on the byte[] somewhere? Why is the RotateTransform moving the image when the center is set to 0.5?
Note that this must be as fast as possible, it is clearly a large image and I am trying to render at 10Hz+, this is why the nieve for-loop Byte array transformation is excluded from the realm of possible.
Thanks as always
~TMII
That’s because you are not rotating about the object’s center but about the point (0.5, 0.5).
See http://msdn.microsoft.com/en-us/library/system.windows.media.rotatetransform.centerx.aspx
If you have access to the image in the code behind, set the RenderTransform manually, and specify the CenterX and CenterY as Image.Width/2.0 and Image.Height/2.0.
You only need to do this when the image changes.