TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
David G
1.5k
224
14.6k
Determining correct box to place image according to ratio
Mar 3 2018 7:24 AM
Hey all I am in need of some help with determines what box I need to place a given image into depending on that images ratio (image width / image height) to the box areas Aspect Ratio (box width / box height).
The code below is what I currently have that I am using to determine this (which does not work)
public
static
Dictionary<
string
, List<
double
>> sizeOfPhotoBoxes =
new
Dictionary<
string
, List<
double
>>()
{
/*
[Width]
| [Height]
| | [Aspact Ratio]
↓ ↓ ↓
KEY: VALUE(s): [1] [2] [3]*/
{
"box1"
,
new
List<
double
> {357, 272, 1.31} },
{
"box2"
,
new
List<
double
> {357, 272, 1.31 } },
{
"box3"
,
new
List<
double
> {365, 460, 0.79 } },
{
"box4"
,
new
List<
double
> {365, 265, 1.38 } },
{
"box5"
,
new
List<
double
> {715, 455, 1.57 } },
{
"box6"
,
new
List<
double
> {360, 465, 0.77 } },
{
"box7"
,
new
List<
double
> {360, 465, 0.77 } },
{
"box8"
,
new
List<
double
> {360, 465, 0.77 } },
{
"box9"
,
new
List<
double
> {540, 290, 1.86 } },
{
"box10"
,
new
List<
double
> {540, 290, 1.86 } }
};
double
RA = (
double
)item.images[0].width / item.images[0].height;
foreach
(var AR
in
sizeOfPhotoBoxes)
{
if
(AR.Value[2] >= RA && AR.Value[2] <= RA)
{
System.Diagnostics.Debug.WriteLine(
"found"
);
}
}
I'm trying to figure out how to loop through my boxes' Aspect Ratio's to determine which box that image should go into according to that image Ratio. Currently with the code above, I am not getting the "found" output.
A few image samples:
1) 960/720 = 1.33
2) 1440/800 = 1.8
3) 1078/1440 = 0.74
4) 2048/1152 = 1.77
So taking the example above:
Image 1 would be best in Box 1 or 2 since that box has a 1.31 Aspect Ratio.
Image 2 would be best in box 9 or 10 since that box has a 1.86 Aspect Ratio.
Image 3 would be best in box 6, 7 or 8 since that box has a 0.77 Aspect Ratio.
Image 4 would be best in box 9 or 10 since that box has a 1.86 Aspect Ratio.
Any help with the code to determine this above would be great! Thanks!!
Reply
Answers (
0
)
SharePoint Document URL document to download Local server
Gridview Header Name Change Dynamicaly