Hey all y'all helpful people (:D),

My Dad talked to me about making a program that would help him. Basically you enter a screen resolution (or video resolution), then it shows you a list of other resolutions with the same ratio. Let's say you have a picture that you want to change to three times less the size: so you enter the current resolution, then it gives you a list of resolutions that will keep the width to height ratio.

I'm not sure if I should use a listbox, a bunch of labels, or really what I should use for the list of resolutions. I'm also not sure how to go about it at all.

So if I could be provided with some code for it, that would be great! Sorry if this is too general of a question, but I'm a newbie :)

~Zephyr~

I would imagine the first thing you would need to do is figure out what the ratio is.

Determining ratios is easy, its basically the percentage of each other. Here's an example:

Back in the days of XVGA and SVGA screen resolutions were usually close to the standard …

Not sure the reliability, but maybe useful: Video Rez from Wikipedia

## All 7 Replies

I would imagine the first thing you would need to do is figure out what the ratio is.

Determining ratios is easy, its basically the percentage of each other. Here's an example:

Back in the days of XVGA and SVGA screen resolutions were usually close to the standard 800 x 600. This is a ratio of 4:3. What that means is, for every 4 units of measure in width, there are 3 of the same units of measure in length.

Some people might say that a ratio is a fraction...that's true, kinda. When talking about a 2 dimensional plane (length and width ONLY or only 2 objects) then it can be thought of that way. But if you had a ratio of 4:3:1 or something, that's different.

Here is how you find a 2D ratio (which is probably what you want):

using 800 x 600 as the example. First we find the absolute value of the different between the two numbers, in this case 200. We then divide each by that number:

|(800-600)| = 200
800/200 = 4
600/200 = 3

4:3 is your ratio for 800 x 600.

Here's another example:

1024 x 768:

|(1024-768)| = 256
1024/256 = 4
768/256 = 3

4:3 is the ratio again.

so that means if 800 x 600 and 1024 x 768 have the same ratio, if you increase 800 and 600 and respect the ratio, you should eventually get 1024 x 678, but there are an infinite number of points between the two, if you wanted to increase 800 to say, 900, then you would do this math:

900/4 = 225
225*3 = 675

900 x 675 is the new resolution. If you check it backwards you should get 4:3

|(900-675)| = 225
900/225 = 4
675/225 = 3

Woo hoo! I love math!

Now as for the resolutions and how to display them? Well...if the computer could calculate them all, the computer would literally enter an infinite loop because numbers are infinite, so you would need some sort of base, and a max resolution.

For example, you could start with 800 x 600, set a base as say 100 (to increase one side by 100 either the 800 or 600) and then a max so that after the computer has added 100 to 800 x amount of times it stops and gives you the resolutions, say like 5 times or something.

If you wanted to stick with screen resolutions (like hardware defined, or monitor resolutions) then I dunno, some monitors support different resolutions than others, same with adapters.

If you are talking about images or videos that are independent of hardware resolutions, I would do what I suggested before and just set a number of iterations and let the user define a base to increase (or decrease) by.

You could also just do a fill in the blank kind of thing and not have a list. Like, have 2 boxes to put in the original resolution, and then 2 more boxes for the desired resolution. The user fills one box in and the computer calculates the other one.

I dunno, just an idea. I saw an opportunity to play with math and took it. Sorry if it wasn't much help :) Good luck!

I would imagine the first thing you would need to do is figure out what the ratio is.

Determining ratios is easy, its basically the percentage of each other. Here's an example:

Back in the days of XVGA and SVGA screen resolutions were usually close to the standard 800 x 600. This is a ratio of 4:3. What that means is, for every 4 units of measure in width, there are 3 of the same units of measure in length.

Some people might say that a ratio is a fraction...that's true, kinda. When talking about a 2 dimensional plane (length and width ONLY or only 2 objects) then it can be thought of that way. But if you had a ratio of 4:3:1 or something, that's different.

Here is how you find a 2D ratio (which is probably what you want):

using 800 x 600 as the example. First we find the absolute value of the different between the two numbers, in this case 200. We then divide each by that number:

|(800-600)| = 200
800/200 = 4
600/200 = 3

4:3 is your ratio for 800 x 600.

Here's another example:

1024 x 768:

|(1024-768)| = 256
1024/256 = 4
768/256 = 3

4:3 is the ratio again.

so that means if 800 x 600 and 1024 x 768 have the same ratio, if you increase 800 and 600 and respect the ratio, you should eventually get 1024 x 678, but there are an infinite number of points between the two, if you wanted to increase 800 to say, 900, then you would do this math:

900/4 = 225
225*3 = 675

900 x 675 is the new resolution. If you check it backwards you should get 4:3

|(900-675)| = 225
900/225 = 4
675/225 = 3

Woo hoo! I love math!

Now as for the resolutions and how to display them? Well...if the computer could calculate them all, the computer would literally enter an infinite loop because numbers are infinite, so you would need some sort of base, and a max resolution.

For example, you could start with 800 x 600, set a base as say 100 (to increase one side by 100 either the 800 or 600) and then a max so that after the computer has added 100 to 800 x amount of times it stops and gives you the resolutions, say like 5 times or something.

If you wanted to stick with screen resolutions (like hardware defined, or monitor resolutions) then I dunno, some monitors support different resolutions than others, same with adapters.

If you are talking about images or videos that are independent of hardware resolutions, I would do what I suggested before and just set a number of iterations and let the user define a base to increase (or decrease) by.

You could also just do a fill in the blank kind of thing and not have a list. Like, have 2 boxes to put in the original resolution, and then 2 more boxes for the desired resolution. The user fills one box in and the computer calculates the other one.

I dunno, just an idea. I saw an opportunity to play with math and took it. Sorry if it wasn't much help :) Good luck!

I do know how to get the ratio, since I just passed that chapter in Geometry and because I'm a math wiz myself :D

Would you use | | for absolute value in C# code? I kind of doubt that.

Also, I don't want to actually change the resolution of the screen. I want to list several possibilities for resolutions that have the same ratio. What's a good control for listing stuff?

Not sure the reliability, but maybe useful: Video Rez from Wikipedia

Lol I saw that too. But I don't need the common resolutions :P

EDIT: Product field should be called Quotient to be accurate. Sorry for any confusion there :)

No, || wouldn't work for absolute value in C#, I believe it's Math.Abs(x);

Like I said though, about listing possibilities...whatever you want is fine, but you need some kind of limiter otherwise the computer will loop infinitely.

Here's some code to show what I would do (it's rough, no promises):

``````using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ResolutionCalculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private int[] GetRatio(int val1, int val2)
{
//find the difference
int Difference = val1 - val2;

//get the abs value
int AbsDifference = Math.Abs(Difference);

//find the first ratio number
int Val1Ratio = val1 / AbsDifference;

//find the second ratio number
int Val2Ratio = val2 / AbsDifference;

//write the ratio to the label
labelRatio.Text = Val1Ratio.ToString() + ":" + Val2Ratio.ToString();

//return our ratio
int[] Ratio = new int[2];
Ratio[0] = Val1Ratio;
Ratio[1] = Val2Ratio;

return Ratio;
}

private void GetSimilarResolutions()
{
//our limiter
int i = 0;

//our maximum iterations
int Iterations = 5;

//our first value

//our second value

//our ratio
int[] Ratio = GetRatio(val1, val2);

//the last value of the length
int LastLength = val1;

//the last value of the width
int LastWidth = val2;

//the string to hold a resolution
string Resolution;

//our product
int Product;

//fill our dropdown box with the resolutions
while (i <= Iterations)
{
LastLength = LastLength + 100;

Product = LastLength / Ratio[0];

LastWidth = Product * Ratio[1];

Resolution = LastLength.ToString() + " x " + LastWidth.ToString();

i++;
}
}

private void buttonDoIt_Click(object sender, EventArgs e)
{
GetSimilarResolutions();
}
}
}``````

Project is attached as well for demonstration purposes.

Eh just realized you need to clear the combobox if you run it twice...easy fix...just wanted to point it out

Thanks for the code, I've got everything I need now. Solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.