Programmatically draw a bitmap to a WPF Canvas? - wpf

How can I programmatically draw a bitmap to a WPF Canvas? (or should I do something else entirely?) I will have about 40 moving images.

If you need to dynamically create and modify bitmaps, then use a WritableBitmap. You can place these on a canvas.

I did something similar, but I wanted some logic on each image(object) so I created a UserControl with an image and just add the UserControl to the canvas.

Related

Drawing shapes, text and images with moving and scaling in WPF

I'm trying to draw simple map in WPF. I need to draw shapes, text and images. It also should be possible to use mouse to move around and zoom in and out.
Right now, I have combination of Canvas + Geometry + Transforms to draw shapes, but I don't know how to add text and images.
I already tried various combination of Canvas/Grid and Layout/Render transform. Biggest problem is adding text and images, because transformations are in geometries.
If i understand you right, you're currently putting Path objects (with transformed Geometries) into a Canvas. For adding text and images you could easily add TextBlock and Image objects to the same Canvas and apply your transformations to their RenderTransform property.
A completely different approach would be to use WPF low-level rendering, provided by the DrawingVisual class. You may start at WPF Graphics Rendering Overview.

How to Resize Controls in silverlight

I am working on a Silverlight application and my problem is like this: I have a StackPanel
and inside the stackpanel I have a ViewBox. Inside the viewbox I am adding images and rotating them 90 and/or -90 degrees.
When rotated, my images go out of the viewbox. How can I fix this?
Use something other than StackPanel, it doesn't resize.
There's a control in the Silverlight Toolkit that addresses this problem called the LayoutTransformer. It ensures that when you change the transform, the bounds of the control are within the LayoutTransformer bounds.
You can see this at work in the Silverlight Toolkit demo. Just scroll down the tree on the left to the Layout section.

How to create a UserControl that is a bitmap in WPF?

I was the functionality of a UserControl but I want it to look like a bitmap. How can I do this in WPF?
What about the Image control? What exactly do you want? How does a bitmap look like? Can you write more than one sentence?
You can do the following
Download source of the Bitmap class that will snap to device pixels from here
Rewrite it a little bit.
a. Set UserControl instead of UIElement as it's parent
b. Rename MeasureCore to MeasureOverride
I hope that will become the thing you need.

How to draw onto a PictureBox image when control resizes?

I am using the pictureBox_Paint event to try and draw an overlay onto the image in a PictureBox.
This is working fine until I resize the PictureBox (set to use SizeMode.Zoom), when I do this the overlay graphic is drawn off position by the margin between the image and the edge of the PictureBox. I guess I need to use the ImageRectangle somehow but this is not public.
I would create a custom usercontrol instead, you would have much more control, and would not be difficult to build.

Erasing in a WPF program

How can I make a MS Paint clone in WPF?
I use Canvas and Shapes, but I don't know how to implement erasing. Should I use different controls, image control for example, or other drawing technology?
You can simply remove the object from the Canvas using canvas.Children.Remove() methods.

Resources