I'm trying to make a simple WPF application where you will be able to crop a video quickly and simply. I want it to look like and operate like how this website does it: https://clideo.com/crop-video
It darkens the video outside of the boundaries and has the rule of thirds guidelines. It can also be freely resized to any aspect ratio. Having the "grab" squares on the corners and sides would be nice but i am not too fussed about that :)
I've had a search already and came across this: http://csharphelper.com/blog/2014/12/let-user-move-resize-rectangle-wpf-c/
It operates great but if you look at the code it doesn't work very nicely and will be messy to implement the dark background I think, it is also from 2014 and there is probably a better way to do this in WPF nowadays. The only way I can think of doing the dark background is to have 4 dark rectangles on the top, right, bottom and left, resizing when you resize the crop area. There is most likely a better way to do this, hence why I am here.
In summary, I'm very new to WPF, not sure where to start, looking for some pointers :)
Related
I'm trying to draw something like the transparent-indicating background when you use Photoshop or other image processing software.
Like I said in the title, I'm using HatchBrush, and the large checker board style is not large enough for me. Beyond that, I would rather like to be able to control how large each tile is based on current zoom factor or other stuff in my environment.
I have also written the code to draw a lot of filled rectangles, but this was way too slow for some reason (this allows me to control tile size though).
I have not tried Texture Brush yet, but to have a texture means I can not change the colors on the fly easily, so I would rather avoid that unless run out of options.
Is there any ways that I can configure HatchBrush or do something more basic but efficient?
I found the answer when looking at WPF. A solution was on their tutorial with brushes.
https://msdn.microsoft.com/en-us/library/aa970904%28v=vs.110%29.aspx
In my WinRT app I need to draw about 3000 objects on a canvas, where I can translate and zoom the view. Unfortunatley, after adding about 1500 lines to my canvas my Windows 8 App always crashes. What could be the best practice to achieve this?
One solution could be rendering everything on an image (how do I do this?). But then I loose comfort of easy access and editing of every element.
Also my scale and translate is very slow. But since I also need a big overview, it makes no sense to put only the objects of the visible area in the canvas, since on minimum zoom it's still everything and zoomed it's still very laggy cause of add and remove operations.
There are a couple of different things you should employ to have a smooth UX:
Use a Quadtree, whenever you add a shape to your canvas you also put it on your Quadtree. This will be helpful when you will zoom on a portion of the image: you will know what objects are in this portion of the image; you will render them again (against using a cached/pixellated version).
To overcome the potentially lengthy drawing process you could do the following:
display the portion of the cached image overview at the right scale
use a progress indicator to let know the user that the program is working render this portion
when the faint rendering is done, blit it on the screen
A concrete example: Google Maps does that.
I'm starting to build a GUI app in C# (.NET 4.0), and find it a little hard to design the graphics.
I want to have one image background to all panels, and resize it automatically so it fit the panel dimensions.
If the image would just stretched normally, then it won't look good since the background image is built in a way of header, frame, center.
So what I want is actually to define the left, top, right, bottom anchors of the rectangle in the image that I want to be stretched.
I thought about overriding PictureBox::OnPaint and continue from there, but it feels too manual for something that suppose to be pretty simple in GUI developments.
So what is the best approach for resizing only the relevant part of the background image?
What I am looking to do in my Windows Forms application (or even WPF). Is to dynamically render an image of a tube, or cylinder (with a 3d look or having some sort of depth for a better visual experience), setting the length and hieght and so on, (also need rulers and such to zoom in and out). But then allow the user to enter some text, which will then be placed on that tube or cylinder, for display purposes, able to scale the text size, to create a visual representation of what it would look like IRL.
Any ideas on where I can start, or some examples I can build off of? This vector type display is new to me, so any help would be appreciated.
This article looked interesting. I would imagine you could tweak it to do what you were after.
http://kindohm.com/technical/WPF3DTutorial.htm
Also I googled "WPF 3D drawing".
If you have the choice WPF is better suited for graphics than WinForms out of the box. Though a good programmer can make WinForms do similar.
I'm looking to make a relatively simple game using solely graphics primitives (Arcs, Lines, Polygons, etc.).
I started doing this in C# by drawing to a Panel, but right now I'm hung up on how all the scaling works in terms of keeping the proportions the same when changing resolutions. Does anyone have any advice and / or tips on how to do something like this?
There are two options:
1 - Scale everything so that it is sized at a certain percentage of the screen/window. For example, if you want your object to be 1/4 of the screen, then it's width is ScreenWidth/4 and height is ScreenHeight/4. The problem with this technique is that a screen's aspect ratio may make things short and fat or tall and wide. Usually this is addressed by determining one dimension and then using the screen's aspect ratio to determine the other dimension. Ie, Width=Height*AspectRatio.
2 - Make everything the same physical dimension. For example, you may want an object to appear exactly 1" by 1". You can use the screen's resolution (dots per inch) to scale your drawings accordingly. The problem with this is that while it may work well for 'average' sized screens, images may be too small on large screens or too large on small screens.
Most games use technique #1 (with compensation made for the aspect ratio). AR was not always a big deal, but now with widescreen monitors being so popular, it's almost required.
Also, like Richard said, WinForms is not great for games (except minesweeper!), but probably okay for teaching yourself.
Not really a helpful answer but, don't use WinForms!!
If you want a good gaming platform, use DirectX, or XNA Game Studio.
You can do this using GDI+, and transforms. For details on using Matrix to do transforms, see this article on CodeProject.
That being said, this is much, much simpler using WPF's drawing options. In addition to being a retained mode model, which is much simpler when doing simple graphics (ie: move an object instead of constantly redrawing), it has some other nice benefits. The main benefit is that everything in WPF is done using floating point values, and is completely scalable, with no extra real effort. For details on this, see Shapes and Basic Drawing with WPF, which includes both drawing and transforming of shapes.