Scaling images in a picture box visual studio - c#

I'm working on a program where you can make 8-bit sprites and then use them to make a map. The problem is when I put them in the picture boxes (used as tiles for the map editor) they become blurred due to the scaling. Is there any way to get around this? (I'm using visual studio windows forms and c#)

Just make sure you set the SizeMode of your PictureBox properly for your scenario.
As you do not want to scale them, I suggest you put them to Normal or Zoom
Normal with align the picture on the TopLeft position of the PictureBox. Zoom will stretch, but maintain the ratio (thus it wont be overly blurry)

Related

How to set portrait aspect ratio for Windows build in Unity

I'm trying to build a unity project for standalone and the game is in portrait configuration. Everything works fine when I test it in the editor, but when I build it, everything UI related is messed up and by that I mean it tries to fit to the screen's aspect ratio causing many buttons and UI elements to be off-screen despite even manually trying to change the screen size by doing Screen.SetResolution(1080, 1920, false); and stopping the game from entering full-screen mode in the build settings so that it would become a portrait aspect ratio but nothing is working. The game itself is working fine which is not a part of UI or any canvas obviously. Any help would be much appreciated!
UI scaling is tricky particularly is you have different aspect ratios, and also if you have different resolutions (although they are different). The most important things from my experience are making sure you've anchored things as reasonably as you can, used layout groups for dynamic content (dropdowns, instantiated elements, etc.) and used the CanvasScaler component on your canvas.
The Canvas Scaler component can be found on your canvas object in the scene, and is the first place to start when dealing with variable screen sizes. . This mode is the best for variable screen sizes, you can set this up to be your preferred screen size and then make your UI fit that size, then automatically scale based on your ideal size.
It's hard to say what is the best way to anchor your UI elements generally speaking, but if you don't want them centred on the middle of the screen it likely isn't the default. I often find anchoring the sides of an area, or corners, is best.
Finally, depending on your platform and handled screen orientations, you can also set device orientation preferences in Player Preferences. . Exactly what you set may depend on your project, but can be an important step in making sure your UI scales correctly for you targets.

How to make Unity Game fit any resolution when resizing the window?

I couldn't find an option to send a picture to better explain what's happening. Here's a Unity Link that has the photos to explain the issue.
I've tried Camera.main.orthographicsize = 4.0f, a solid number to stay on but the Orthographic Size of the camera keeps changing it's size after resizing the window when I'm in free aspect Unity editor mode and even when I export the Unity game with 1920x1080(16:9) resolution. I want it to stay the same size when resizing the window so that the game can always fit inside the screen in any resolution when resizing the window. The default blue background of the camera displays when I stretch the window's width far enough which I don't want to happen.
This Youtube video has the results I'm looking for but the code unfortunately is not working on Unity 2019. The code provided from this video does entirely different things for me and doesn't solve my issue.
From what I understood is that the screen has to has a fixed resolution.
This link will demonstrate the solution. https://docs.unity3d.com/Manual/GameView.html
It does that by changing the
Game View Aspect from free to a fixed resolution.
Unless this is not what you are looking for then I sugest another solution:
Make a black background image that fits the screen size.
Then change the scale of the objects in the scene relative to the camera.
This link will make the scaling solution, Make object visual size constant despite the distance

Don't auto scale zoomable picture box

I’m writing in c# with Visual Studio 2013. I need to have a pixelPictureBox that the user can zoom (1:1 only) and move what parts show. I also want to make the window it’s in scalable and allow more or less room for the picture. However, this is causing white space to be added when the 2 shapes don’t match, which is not OK. I can take care of properly scaling the pixelPictureBox, but I need to stop the automatic scale from happening. Is there any way to do this? Thanks!
This looks like it's actually a problem with the display panel size and the image size. Before I've zoomed it, the image is bigger than the display area but it still wiggles with a bit of white space when the user drags it one way or the other.

Drawing a lot of lines and other shapes in WinRT App

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.

stretch only certain part in the image when resize

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?

Categories