Search code examples
c#hashcodegethashcodegetimagedata

Converting url to hash code for Image using C#


For my Project I need to convert the Image from Url to hash code. Like "CE3222F5.jpg". But I am not getting where should I implement Gethashcode method in my code. My code to get the image from url is as

Poi.Images = new List<string> { new WikiImage().GetImage(PoiName).Image };

with this code I got my images like this-

"Images": [
"https://upload.wikimedia.org/wikipedia/commons/thumb/6/6b/Nordertor_im_Schnee_%28Flensburg%2C_Januar_2014%29.JPG/266px-Nordertor_im_Schnee_%28Flensburg%2C_Januar_2014%29.JPG"

]

but I want to get it in this way-

"Images": [
"CE3222F5.jpg"

]

I know for this Hash code I need to use

 var hash = uri.GetHashCode();
                var path = Path.Combine(Jpeg, hash.ToString("X") + ".jpg");

But I am not getting how can Iimplement it in my code.


Solution

  • To process a list of strings, you can use Select.

    var images = new List<string>() { "http://www.example.com/image" };
    var hashcodes = images.Select(t => string.Format("{0:X}.jpg", t.GetHashCode()));