0

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.

harry.luson
  • 247
  • 7
  • 19
  • 1
    Your 'question' is not really clear. What are you trying to do exactly? What doesn't work / what's the problem? What did you try so far to overcome it? – Mathieu Feb 17 '16 at 13:38
  • @Mathieu I modified ma question andexplained indetains inside the code what I want to do – harry.luson Feb 17 '16 at 13:46
  • @Mathieu. In my previous code I create folder for image. And download as hash code from wikipedi api. I converted the image uri to hash code . And then in the json serialization class I again get this image from directory and serialize with other object. But Now I want to directly get the image as hash code to json serialization class – harry.luson Feb 17 '16 at 13:49
  • I think your question is why this line doesn't work: `Poi.Images = new List { Jpeg_File[].GetHashCode()}; //I got an error cannot convert int to string.` Can you please elaborate why do you want this? – Leonardo Herrera Feb 17 '16 at 13:49
  • @LeonardoHerrera I have explained in detail in my code. So, In my previous code, in the GetImage Class I create a folder to download the image , which I got after deserialize wikipedia api for image source. then I stored the images in that folder. But Now I do not want to do that. I do not want to store the image in a storage. I want to know Can I do it directly in the json serialization class. I mean Can I get the info.image as per Get Image class in the JsonSerialization class and convert it to hash code. – harry.luson Feb 17 '16 at 13:57
  • @harry.luson you haven't explained much, and you are giving way too much useless details to answer properly. It is useless to us to know where did you get your image from, or where did you store it, or what kind of Json library are you using. So, my guess is, you have an image (I imagine is this `ImgRootobject` that I have no idea what it is) and you want to store as... what? – Leonardo Herrera Feb 17 '16 at 14:05
  • I want to get info.Image in ToJsonForLocation method as hashcode . so for this at first I write this line var Jpeg_File = new WikiImage().GetImage(PoiName).Image; and now I am facing problem in this line Poi.Images = new List { Jpeg_File[0].Name}; I can give my example of image as hashcode "Images": [ "CE3222F5.jpg" ] – harry.luson Feb 17 '16 at 14:13
  • Please, stop answering with useless details - so far, you are saying that *all* you want to do is to convert an int to a hex string? Like, `var filename = String.Format("{0:X}", Jpeg_File[0].GetHashCode());`? What is the use of that? – Leonardo Herrera Feb 17 '16 at 14:27
  • @LeonardoHerrera I just delete my "Useless" details. and modified my question and code everything – harry.luson Feb 17 '16 at 14:35

2 Answers2

2

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()));
Leonardo Herrera
  • 8,388
  • 5
  • 36
  • 66
0

I'm not sure what methods this ImageInfo class offers, but if you can convert your image data to a byte array, you can then convert it to a Base64 string:

Convert.ToBase64String(_byte[] array)

The Base64 string can safely be serialized to JSON.

Christophe
  • 354
  • 3
  • 16
  • I have added Imgaeinfo class in my question. And I do ont need base 64 hashcode. I only need CE3222F5.jpg this type of hash code which I mentioned in my code – harry.luson Feb 17 '16 at 13:37