22using System . Collections . Generic ;
33using System . Diagnostics ;
44using System . Drawing ;
5+ using System . Drawing . Drawing2D ;
56using System . Drawing . Imaging ;
67using System . IO ;
78using System . Linq ;
2223using RestSharp ;
2324using static Kantan . Diagnostics . LogCategories ;
2425
26+ #pragma warning disable CA1416
2527// ReSharper disable ConvertIfStatementToReturnStatement
2628// ReSharper disable CognitiveComplexity
2729// ReSharper disable PossibleNullReferenceException
@@ -95,6 +97,11 @@ public static string Download(Uri src, string path)
9597
9698 try {
9799 wc . DownloadFile ( src . ToString ( ) , combine ) ;
100+ // WebUtilities.GetFile(src.ToString(), combine);
101+ // using var h = new HttpClient();
102+ // h.DownloadFile(src.ToString(), combine);
103+
104+
98105 return combine ;
99106 }
100107 catch ( Exception e ) {
@@ -205,8 +212,8 @@ public static async Task<List<string>> FindDirectImages(string url, int count =
205212 return images ;
206213 }
207214
208- public static bool IsImage ( string url , DirectImageCriterion directCriterion = DirectImageCriterion . Binary ) =>
209- IsImage ( url , TimeoutMS , directCriterion ) ;
215+ public static bool IsImage ( string url , DirectImageCriterion directCriterion = DirectImageCriterion . Binary )
216+ => IsImage ( url , TimeoutMS , directCriterion ) ;
210217
211218 public static bool IsImage ( string url , long timeout , DirectImageCriterion directCriterion )
212219 {
@@ -221,7 +228,7 @@ public static bool IsImage(string url, long timeout, DirectImageCriterion direct
221228 return false ;
222229 }
223230
224- var response = Network . GetResponse ( u . ToString ( ) , ( int ) timeout , Method . HEAD ) ;
231+ var response = HttpUtilities . GetResponse ( u . ToString ( ) , ( int ) timeout , Method . HEAD ) ;
225232
226233 if ( ! response . IsSuccessful ) {
227234 return false ;
@@ -285,6 +292,44 @@ public static DisplayResolutionType GetDisplayResolution(int w, int h)
285292 } ;
286293
287294 }
295+
296+ public static Bitmap ResizeImage ( Bitmap mg , Size newSize )
297+ {
298+ // todo
299+ double ratio = 0d ;
300+ double myThumbWidth = 0d ;
301+ double myThumbHeight = 0d ;
302+ int x = 0 ;
303+ int y = 0 ;
304+
305+ Bitmap bp ;
306+
307+ if ( ( mg . Width / Convert . ToDouble ( newSize . Width ) ) > ( mg . Height / Convert . ToDouble ( newSize . Height ) ) ) {
308+ ratio = Convert . ToDouble ( mg . Width ) / Convert . ToDouble ( newSize . Width ) ;
309+ }
310+ else {
311+ ratio = Convert . ToDouble ( mg . Height ) / Convert . ToDouble ( newSize . Height ) ;
312+ }
313+
314+ myThumbHeight = Math . Ceiling ( mg . Height / ratio ) ;
315+ myThumbWidth = Math . Ceiling ( mg . Width / ratio ) ;
316+
317+ //Size thumbSize = new Size((int)myThumbWidth, (int)myThumbHeight);
318+ Size thumbSize = new Size ( ( int ) newSize . Width , ( int ) newSize . Height ) ;
319+ bp = new Bitmap ( newSize . Width , newSize . Height ) ;
320+ x = ( newSize . Width - thumbSize . Width ) / 2 ;
321+ y = ( newSize . Height - thumbSize . Height ) ;
322+ // Had to add System.Drawing class in front of Graphics ---
323+ System . Drawing . Graphics g = Graphics . FromImage ( bp ) ;
324+ g . SmoothingMode = SmoothingMode . HighQuality ;
325+ g . InterpolationMode = InterpolationMode . HighQualityBicubic ;
326+ g . PixelOffsetMode = PixelOffsetMode . HighQuality ;
327+ Rectangle rect = new Rectangle ( x , y , thumbSize . Width , thumbSize . Height ) ;
328+ g . DrawImage ( mg , rect , 0 , 0 , mg . Width , mg . Height , GraphicsUnit . Pixel ) ;
329+
330+ return bp ;
331+
332+ }
288333 }
289334
290335 public enum DirectImageCriterion
0 commit comments