I have an image on which I may use a ScaleTransform to increase the image size by 25%. I also have a rectangle which sits on top of the image highlighting a particular area. When I scale the image I want the rectangle to scale as well and highlight the same area as before. Scaling the rectangle itself isn't the issue, it's getting the rectangle into the correct position so that it highlights the same area. How do I do this? Is there a mathematical formula of some description that can be used to calculate its correct position?
Apply the same scaling factor to the X and Y offsets of the rectangle.
Related
I'm creating a 2D project and I've a particular sprite that when I import it to Unity I apply a 200 units per pixels in the importer and in runtime sometimes I scale it.
How can I know the actual dimensions of the rendered sprite?
Sprite width in pixels / pixels per unit * X scale = actual width
Do the same for height to get the size in both dimensions.
If you want to get the width of the sprite projected on the screen then you will need to modify the result depending on the camera size. I think you could just divide it by the camera size.
I want to fill a slice of a rectangle based upon a value which doesn't correlate to the degree of the rectangle that needs to be filled.
Say this square below, I would want the area that is light gray to get bigger and bigger (Like a slice of a pie getting bigger) until the entire square is light gray.
How would I go about doing this using System.Drawing? I tried using FillPie but it doesn't fill the square corners
Set the Graphics.Clip property to a region that represents the rectangle, then FillPie with an oversized radius such that the "pie" completely covers the rectangle.
I need an advice in image processing. I have WF application coded in C# which finds me a coordinates by given parameters and based on this coordinates I would like to crop the image to a circle and unfold this circle to a rectangle.
So just to summarize my questions - How should I correctly crop the image in pictureBox to a circle (ellipse) image and how to unfold this circle to a rectangle?
I hope I described my problem well and I will be very grateful for every advice about how should I continue.
I guess you want the image to be cropped to a circle and then have that circle expand to a rectangle?
This would be the way to do it:
http://msdn.microsoft.com/en-us/library/system.windows.uielement.clip.aspx
You then just animate the EllipseGeometry to make it bigger than the image and then maybe remove the clip if you like.
I'm developing an UI for a project for school, and I've tried similar methods to scaling my texture as listed here, but here is the issue:
Our project is developed at 1440 x 900, so I've made my own images that fit that screen resolution. When we have to demo our project in class, the projector can only render up to 1024 x 768, thus, many things on the screen goes missing. I have added window resizing capabilities, and I'm doing my scaling like this. I have my own class called "button" which has a texture 2d, and a Vector2 position contruscted by Button(Texture2d img, float width, float height).
My idea is to set the position of the image to a scalable % of the window width and height, so I'm attempting to set the position of the img to a number between 0-1 and then multiply by the window width and height to keep everything scaled properly.
(this code is not the proper syntax, i'm just trying to convey the point)
Button button = new Button(texture, .01, .01 );
int height = graphicsdevice.viewport.height * button.position.Y;
int width = graphicsdevice.viewport.width * button.position.X;
Rectangle rect = new Rectangle(0,0,width, height);
sprite.being()
sprite.draw (button.img, rect, color.white);
sprite.end
it doesn't end up scaling anything when i go to draw it and resize the window by dragging the mouse around. if i hard code in a different bufferheight and bufferwidth to begin with, the image stays around the same size regardless of resolution, except that the smaller the resolution is, the more pixelated the image looks.
what is the best way to design my program to allow for dynamic texture2d scaling?
As Hannesh said, if you run it in fullscreen you won't have these problems. However, you also have a fundamental problem with the way you are doing this. Instead of using the position of the sprite, which will not change at all during window resize, you must use the size of the sprite. I often do this using a property called Scale in my Sprite class. So instead of clamping the position of the sprite between 0 and 1, you should be clamping the Size property of the sprite between 0 and 1. Then as you rescale the window it will rescale the sprites.
In my opinion, a better way to do this is to have a default resolution, in your case 1440 x 900. Then, if the window is rescaled, just multiply all sprites' scaling factors by the ratio of the new screensize to the old screensize. This takes only 1 multiplication per resize, instead of a multiplication per update (which is what your method will do, because you have to convert from the clamped 0-1 value to the real scale every update).
Also, the effects you noticed during manual rescale of the sprites is normal. Rescaling images to arbitrary sizes causes artifacts in the rendered image because the graphics device doesn't know what to do at most sizes. A good way to get around this is by using filler art during the development process and then create the final art in the correct resolution(s). Obviously this doesn't apply in your situation because you are resizing a window to arbitrary size, but in games you will usually only be able to switch to certain fixed resolutions.
I have an array of Point variables. When drawn using Graphics.DrawLine, they create the expected image. My problem is that 0,0 is actually the center of the image (not the top left of my canvas as expected. My X and Y coordinates in the Points can contain negative numbers.
When I try to draw this to my Image, of course I get 1/4 of the total image as the remainder is drawn outside the bounds of my canvas. How do I center this drawing correctly onto my canvas?
I know the dimensions of the image I want to draw. I know where 0,0 is (width / 2, height / 2).
I suppose I can translate each and every single Point, but that seems like the hard way to do this.
TranslateTransform() can map coordinates for you if you setup a transformation during your drawing handlers.
Graphics.TranslateTransform # MSDN
Or, map your coordinates by adding half the width and half the height of the desired viewing area to each coordinate.
Also, you may need to scale your coordinates. You may use Graphics.ScaleTransform to do this.
Graphics.ScaleTransform # MSDN
If you don't wish to use this, then you should divide X coordinates by the percent amount you wish to stretch the width, and divide Y coordinates by the percent amount you wish to stretch the height. This gives us 1 for 100%, 1.2 for 120%, 0.8 for 80%, etc.
Welcome to the Windows' version of the Cartessian Plane. Your last statement is correct. You do have to offset each and every point. The only real help you can give yourself is to make the offset logic a separate method to clean up your main drawing code.
When creating the array, add an offset to each x value equal to half of the width and an offset to y equal to half of the height. That way when the points are drawn, they're in the expected position.