I am looking for a control for cropping images as it is in eg. IrfanView (Drawing rectangle with possibility to move individual sides). I have not found anything like this. Does such control exists?
You should have a look at the CroppedBitmap class, there are several tutorials out there explaining how to use it. This example uses it with an adorner in order to visually select the area that should be cropped.
Related
I'm trying to make a chamfered corner on a custom control for Windows Phone 8. I'd like to achieve something much like the following:
http://jdcard.com/engl3007/arpln02.gif (I cannot post images yet because of my reputation)
I know it's possible to create a rounded corner, but I haven't had much luck at creating a chamfered corner. I'd like the corner to be only on the bottom right. The control should resize according to its contents.
Why not just create a control which puts an image with the desired effect in the background and aligned to the appropriate corner?
I need to load an image in a WPF window, an be able to read and modify individual pixels (in an efficient way), zoom the image (and scroll it), get the value RGB/grayscale of the pixel under the cursor, select areas (I guess knowing the cursor position and being able to modify pixels I could draw myself the square which represents the selected area)...
What is the best combination of WPF controls and classes to accomplish this?
I've been trying to do it loading a System.Windows.Media.Imaging.BitmapImage and putting it into a System.Windows.Controls.Image, but it's taking much longer than I expected.
Thank you very much
I once used this WPF Interactive Image Cropping Control. Go check it out, it should at the very least give you a good place to start. Oh, and welcome to Stackoverflow. :)
I am using c# winforms to show an Image. The displaying of the image is done using a user control. Now I want to provide the user to draw lines, put other small images, write text etc over the image on an overlay control. How can I provide this functionality? If I use another user control to show the overlay control with transparent back, will that work?? any other solution will be welcome.
You might try approaching this with a canvas (Panel) that handles painting the image as the background and all the annotations/markup afterwards. This will make the foreground appear to be transparent. I expect you'll want to set Control.DoubleBuffer for performance.
You might experiment with setting the style ControlStyles.AllPaintingInWmPaint. Also, try overriding Control.OnPaintBackground and do nothing, and override Control.OnPaint and do all your painting inside there.
If performance is still unacceptable, pay close attention to the PaintEventArgs.ClipRect property. This is the only area you need to paint. The trick is figuring out which of your annotations/overlays intersect with this rectangle and painting them in the correct order.
Either this canvas or a higher level control will need to track mouse movement so you know where to draw the lines, paste images, etc.
I want to do basic WPF graphics, i.e. rectangles, lines, circles and text.
When should I use Drawing and when should I use a DrawingVisual?
I have some code that uses Drawing and I render those to a DrawingImage and display that in an image control. Is this the right way? I could not see how to add text to a drawing. I had trouble positioning it too. Should I be rendering to a Canvas?
I have some code that uses DrawingVisual and writes to a DrawingContext. That is like WinForms. Is this the recommended way?
Do you have any high level advice on which APIs to use for basic graphics and labels? Will they options work on Silver Light and Desktop?
You mention in your comment that you're actually implementing scatter plots or similar graphs. Typically in WPF this is created by templating the existing controls, like a listview. It sounds counterintuitive, but this is far easier and more powerful than drawing your own.
This article by Charles Petzhold shows a scatter plot implemented in this way and goes into great detail about how to make it performant to 10,000+ data points.
You'll most likely want to just render to a Canvas. If you add "shapes" to a canvas, WPF will handle all of the drawing for you.
For details, see Shapes and Basic Drawing in WPF.
I would like to learn about creating a program that I could draw simple shapes and be able to select them for editing - like resizing, order of display, color change. Is there an online resource that someone knows of that would help me reach my goals.
thanks
"GDI+" is what you are looking for. You can start here: http://msdn.microsoft.com/en-us/library/da0f23z7.aspx
A sneaky way I used to do it was to create a custom control, remove the background from it and paint my shapes and sizes on it. Then, you can easily implement selection (override OnClick), dragging and resizing (OnMouseDown, OnMouseMove, OnMouseUp). You can then implement options like color, etc. by means of a property (see Browsable attribute and property get/setters) and a PropertyGrid control.
Anything beyond that, though - Bezier curves and such - would need something a tad more advanced, though.
The alternative is to only use such controls for the sizing handles, and do all the drawing on one central canvas - the only drawback then is figuring out how to select a shape on the canvas.