Any way to snap animated TranslateTransform to pixel grid? - c#

Is there any way to snap animated TranslateTransform to pixel grid?
There is a very bad jittering, when moving text using animation. I guess it's because of subpixel positioning. I need to avoid this jittering. Suggest possible ways.

It sounds like you want TextOptions.TextHintingMode="Animated" in your XAML. See http://msdn.microsoft.com/en-us/library/system.windows.media.textoptions.texthintingmode(v=VS.95).aspx for more details.

Dave Relyea posted an article on how to implement a pixel snapping control in Silverlight. This is a control which listens to the LayoutUpdated event to perform pixel snapping on child elements. Perhaps this is what you're looking for; hopefully without too much modification :)

Why won't you render thit text to WritableBitmap like this:
WriteableBitmap wb = new WriteableBitmap(textToTranslate, null);
Then place this bitmap into Image and translate image instead?

What are you trying to do exactly? Do pixel snapping using drag'n'drop? If so, you just could call the method that does the translate if the coordinate is a multiple of a certain number.
A small example of what you are trying to do would also be helpful.

Related

Properly Scale UI Images in Unity

I have a png that's size 150x100 , and I set the UI image to the same, but it makes a bunch of extra space around it (that can be interacted with). How do I fix this?
Image of Problem: https://imgur.com/a/2ILXY1t
Unity isn't adding extra space. The image itself HAS that space.
There are options to crop out the alpha space in Unity by using the sprite editor, but by my experience i prefer using a proper Image editor like Gimp. using one is the best way to handle your image assets.
To crop out the extra space you just have to reduce the canvas size.
Well, first you could check (in Unity) wether your Image has its property Preserve Aspect set to True.
You could click Set Native Size which is right below it, so the 'box' around your image will take it's size.
Edit: Nevermind the first two. I do not know why i thought they could solve it, i looked at your image again and i, too, think there are transparent pixels above and below it. So you should try this:
Then you could check whether your picture has any transparent pixels around it, using an image editor. If it has, you would need to cut them out.

How do I get the dimensions of the ImageRectangle in PictureBox?

Background
I want to be able to get the drawn dimensions of a zoomed image inside the picturebox (I'll explain below).
The PictureBox.ImageRectangle property seems to be exactly what I'm looking for because it shows the height and width of the resized image, as well as it's relative top, left position inside the control.
The trouble is PictureBox.ImageRectangle is private and so I can't read the values without using reflection (which is obviously not ideal).
Actual Question
My question is, is there another way that I can easily get to these values without writing a method to calculate what the values "ought" to be? I can do that easily enough, but I feel I'd be reinventing the wheel.
Context:
I'm writing a simple image processing app in C# and one of the things it has to do is allow the user to draw a selection around a portion of the image (a lot like the Marquee tool in Photoshop).
I need to know the dimensions of the rendered image so I know where to set the bounds of my marquee tool and also to translate the values of the drawn rectangle to points on the scaled bitmap inside the control.
My answer look simple so maybe I'm missing something, but I think Control.DisplayRectangle suits your need.
EDIT
OK, missed the point; however see How to get the value of non- public members of picturebox?
if you want to access dimension of the image in picture box you can use
GraphicsUnit units = GraphicsUnit.Point;
RectangleF imgRectangleF = pictureBox1.Image.GetBounds(ref units);
Rectangle imgRectangle = Rectangle.Round(imgRectangleF);

Image rescale (downsize) with Silverlight

I have an array of graphs, that are 2000x1000 pixels pngs. When I put them into a silverlight Image that auto-sized with the browser window, DisplayImage.Source = new BitmapImage(GetHeatmapURL()); they images look distorted and for some browser sizes much worse than for some others.
I want to fiddle with some setting that would improve the quality of this downsampling, is this possible? Am I doing something wrong? My first approach was to put the Image into a Viewbox. That looked even worse. Googling gives virtually nothing useful...
Any help much appreciated.
PS. I'm working with Silverlight 4.
You could check out the WriteableBitmapEx project on CodePlex which gives you a Resize() extension method for the Silverlight WritableBitmap class where you can use either Bilinear or Nearest Neighbor interpolation. Resizing with the Bilinear interpolation might give you something that looks better than the ViewBox resizing, but you would have to test it out.
var resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
When making use of the Viewbox you need to make sure to set Stretch to Uniform to respect the original height/width ratio.
In regards to the rendering of the image at the given aspect ratio and size; that is contingent on the framework.

OpenTK text animation

Does anybody know how to do, or where to find some good examples, for scrolling (animating) 2D text using OpenTK framework. I need something like bottom (top) scrolling tickers on news TV channels.
Thanks.
There are many possible approaches to text rendering. The simplest one: use System.Drawing to render your text into a System.Drawing.Bitmap. Afterwards, load this Bitmap into an OpenGL texture and splat it onto a quad for rendering. Animate the text by moving this quad and update the Bitmap/texture whenever the text changes.
Edit: I have written a text rendering example for OpenTK, which you can find here: http://opentk.svn.sourceforge.net/viewvc/opentk/trunk/Source/Examples/OpenGL/1.x/TextRendering.cs?revision=3063&view=markup
Copy the TextRenderer class to your own project and you are good to go. Check the example for usage instructions.

Drawing on WriteableBitmap

I have a WriteableBitmap and would like the user to be able to draw over it as if it was an InkPresenter control. What is the best way to go about doing this in realtime? Using WriteableBitmap.Pixels, I'm able to access each pixel, but when I try to edit them during the MouseMove event, it seems very slow, and only changes one pixel at a time. Are there any libraries or methods to help make this process easier? thanks
Try this..
http://writeablebitmapex.codeplex.com/

Categories