Skip to content

Commit b42c4d0

Browse files
committed
v1.6.3.1
1 parent 6882a83 commit b42c4d0

File tree

6 files changed

+86
-8
lines changed

6 files changed

+86
-8
lines changed

IMDbAPI_Client/IMDbAPI_Client.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
<ApplicationIcon>ProjectIcon.ico</ApplicationIcon>
5252
</PropertyGroup>
5353
<ItemGroup>
54-
<Reference Include="IMDbApiLib, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
55-
<HintPath>..\packages\IMDbApiLib.1.6.2\lib\net45\IMDbApiLib.dll</HintPath>
54+
<Reference Include="IMDbApiLib, Version=1.6.3.1, Culture=neutral, processorArchitecture=MSIL">
55+
<HintPath>..\packages\IMDbApiLib.1.6.3.1\lib\net45\IMDbApiLib.dll</HintPath>
5656
</Reference>
5757
<Reference Include="MetroFramework, Version=1.4.0.0, Culture=neutral, PublicKeyToken=5f91a84759bf584a, processorArchitecture=MSIL">
5858
<HintPath>..\packages\MetroModernUI.1.4.0.0\lib\net\MetroFramework.dll</HintPath>
@@ -86,6 +86,7 @@
8686
<DependentUpon>MainForm.cs</DependentUpon>
8787
</Compile>
8888
<Compile Include="Models\ClientOptions.cs" />
89+
<Compile Include="Models\ClientUtils.cs" />
8990
<Compile Include="Models\GridData.cs" />
9091
<Compile Include="Models\Enums.cs" />
9192
<Compile Include="PingForm.cs">
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Drawing;
3+
using System.Drawing.Imaging;
4+
using System.IO;
5+
6+
namespace IMDbAPI_Client
7+
{
8+
public class ClientUtils
9+
{
10+
public static byte[] ImageToBytes(Image img)
11+
{
12+
return ImageToBytes(img, ImageFormat.Png);
13+
}
14+
15+
public static byte[] ImageToBytes(Image img, Size size)
16+
{
17+
if (img == null)
18+
return null;
19+
20+
if (img.Width > size.Width || img.Height > size.Height)
21+
img = ResizeImage(img, size);
22+
23+
return ImageToBytes(img, ImageFormat.Png);
24+
}
25+
26+
public static byte[] ImageToBytes(Image img, ImageFormat imgFormat)
27+
{
28+
if (img == null)
29+
return null;
30+
31+
var ms = new MemoryStream();
32+
img.Save(ms, imgFormat);
33+
return ms.ToArray();
34+
}
35+
36+
public static Image BytesToImage(byte[] bytes)
37+
{
38+
if (bytes == null)
39+
return null;
40+
41+
var ms = new MemoryStream(bytes);
42+
var returnImage = Image.FromStream(ms);
43+
return returnImage;
44+
}
45+
46+
public static Image BytesToImage(byte[] bytes, Size size)
47+
{
48+
if (bytes == null)
49+
return null;
50+
51+
var img = BytesToImage(bytes);
52+
if (img.Width > size.Width || img.Height > size.Height)
53+
return ResizeImage(img, size);
54+
55+
return img;
56+
}
57+
58+
public static Image ResizeImage(Image img, Size size)
59+
{
60+
var ratioX = (double)size.Width / img.Width;
61+
var ratioY = (double)size.Height / img.Height;
62+
var ratio = Math.Min(ratioX, ratioY);
63+
64+
var newWidth = (int)(img.Width * ratio);
65+
var newHeight = (int)(img.Height * ratio);
66+
67+
var newImage = new Bitmap(newWidth, newHeight);
68+
69+
using (var graphics = Graphics.FromImage(newImage))
70+
graphics.DrawImage(img, 0, 0, newWidth, newHeight);
71+
72+
return newImage;
73+
}
74+
}
75+
}

IMDbAPI_Client/MoreInfoForm.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,16 @@ private async void MoreInfoForm_Shown(object sender, EventArgs e)
8181

8282
data.Image = data.Image.Replace("/original/", "/224x308/");
8383
using (var wc = new WebClient())
84-
picPoster.Image = Utils.BytesToImage(await wc.DownloadDataTaskAsync(data.Image));
84+
{
85+
picPoster.Image = ClientUtils.BytesToImage(await wc.DownloadDataTaskAsync(data.Image));
86+
}
8587

8688
foreach (var act in data.ActorList.Take(6))
8789
{
8890
var uc = new CastUserControl();
8991
act.Image = act.Image.Replace("/original/", "/96x132/");
9092
using (var wc = new WebClient())
91-
uc.CastImage = Utils.BytesToImage(await wc.DownloadDataTaskAsync(act.Image));
93+
uc.CastImage = ClientUtils.BytesToImage(await wc.DownloadDataTaskAsync(act.Image));
9294
uc.CastName = act.Name;
9395
uc.CastAsCharacter = act.AsCharacter;
9496

IMDbAPI_Client/SearchForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private async void lbSearchMovie_SelectedIndexChanged(object sender, EventArgs e
164164
item.Image = item.Image.Replace("/original/", "/224x308/");
165165
using (var wc = new WebClient())
166166
{
167-
picPoster.Image = Utils.BytesToImage(await wc.DownloadDataTaskAsync(item.Image));
167+
picPoster.Image = ClientUtils.BytesToImage(await wc.DownloadDataTaskAsync(item.Image));
168168
}
169169
EnableControlls(true);
170170
}

IMDbAPI_Client/UserControls/Step4_DownloadUC.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,15 @@ await _apiLib.DownloadReportAsync(
203203
{
204204
ReportCurrent("Posters", current, total, cancellationToken.IsCancellationRequested);
205205
string filePath = Path.Combine(dir, $"{item.Id}-{index.ToString("000")}.jpg");
206-
await Utils.DownloadFileAsync(filePath, p.Link, _apiLib.WebProxy);
206+
await Utils.DownloadFileAsync(filePath, p.Link, null, _apiLib.WebProxy);
207207
current++;
208208
index++;
209209
}
210210
foreach (var p in data.Posters.Backdrops)
211211
{
212212
ReportCurrent("Posters", current, total, cancellationToken.IsCancellationRequested);
213213
string filePath = Path.Combine(dir, $"{item.Id}-{index.ToString("000")}.jpg");
214-
await Utils.DownloadFileAsync(filePath, p.Link, _apiLib.WebProxy);
214+
await Utils.DownloadFileAsync(filePath, p.Link, null, _apiLib.WebProxy);
215215
current++;
216216
index++;
217217
}

IMDbAPI_Client/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="IMDbApiLib" version="1.6.2" targetFramework="net472" />
3+
<package id="IMDbApiLib" version="1.6.3.1" targetFramework="net472" />
44
<package id="MetroModernUI" version="1.4.0.0" targetFramework="net472" />
55
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
66
</packages>

0 commit comments

Comments
 (0)