c# get largest images out of json file

  • Thread starter Thread starter elfenliedtopfan55
  • Start date Start date
E

elfenliedtopfan55

Guest
hello i have code that is meant to get the highest images from a json file that has multiple images in there but for some strange reason its picking up images that are small like 64x64 when it should be picking the highest one there example is this one.

7pgVOqL.png

as you can see that is showing 64x64

but you can find a bigger one in the files aka here.

json file i reading form

and here is the line it should be getting but seems to be finding the 64x64

{
"createdAt": "2018-11-30T10:01:00.303206",
"size": 551565,
"options": {
"quality": 88,
"format": "RGB"
},
"uid": "8d5b5bde60e94019950d2034e6d1dcc7",
"updatedAt": "2019-10-14T19:37:53.942458",
"width": 2048,
"url": "https://media.sketchfab.com/models/...3ec5c03/8d5b5bde60e94019950d2034e6d1dcc7.jpeg",
"height": 2048
},



but it seems to be finding and downloading this one.

"createdAt": "2018-04-18T05:35:08.885903",
"name": "SMG_Exploded_SMG_Body_Mat_BaseColor.png",
"uid": "47311a6926554051b9a84d6b03ec5c03",
"updatedAt": "2019-10-14T19:37:54.345052",
"images": [
{
"createdAt": "2018-11-30T10:01:00.603627",
"size": 2739,
"options": {
"quality": 95,
"format": "RGB"
},
"uid": "257ba602b6254fef8dc1ffe8cde3ae50",
"updatedAt": "2019-10-14T19:37:53.131984",
"width": 64,
"url": "https://media.sketchfab.com/models/...3ec5c03/257ba602b6254fef8dc1ffe8cde3ae50.jpeg",
"height": 64
},



this is the code below that is using to download the highest one.

public void Images()
{
string sampleJson = File.ReadAllText(Application.StartupPath + @"\Model.json");
JObject sample = (JObject)JsonConvert.DeserializeObject(sampleJson);
JToken texture = sample["/i/models/"+ Sachiko_Res.TextureID +"/textures?optimized=1"];
foreach (JToken result in texture["results"])
{
Name = result["name"].ToString();
JToken largestImage = null;
foreach (JToken currentImage in result["images"])
{
Url = currentImage["url"].ToString();
Hight = currentImage["height"].ToString();
Width = currentImage["width"].ToString();

if (largestImage == null)
{
largestImage = currentImage;
Downloadtextures();
}
else
{
int currentImageSize = Convert.ToInt32(currentImage["width"]) * Convert.ToInt32(currentImage["height"]);
int largestImageSize = Convert.ToInt32(largestImage["width"]) * Convert.ToInt32(largestImage["height"]);
if (largestImageSize < currentImageSize)
{
largestImage = currentImage;
}
}
}
}
String s = Url;
String[] results = s.Split('/');
TextureID2 = results[5];
MessageBox.Show("Download Compleate");
}

basically what i want it to do is download the highest resolution of the texture they have multiple image resolutions for each texture

want to read file and go though each one fine the most highest resolution and download that image and when it moves onto the next image want it to do the same find the higest res and download that to the end so i am left with images that are like 2048x2048 as of the pose of 64x64 when there is a higher res it should download not sure what its not doing this.

any help would be much appreciated.

elfenliedtopfan5

Continue reading...
 
Back
Top