Skip to content

Store image into memory

George George

Asked Nov 26, 2008, 3:19 AM EST3 answers
Share
LinkedInX

Hello everyone,

I have some phone to each user and I want to store all photos into memory with key-value pair. Key is the user name and value is the binary photo stream. Any ideas how to store binary photo content into memory? Which data structure is suitable to be used?

thanks in advance,

George

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    +1

    For the first question use MemoryStream object to set bytes in the memory

    For the second question use a dictionary object

    +1
  • +1
    Thanks Bechir!

    Could I just use byte[] other than using MemoryStream? Any pros of using MemoryStream?

    byte[] imageData = System.IO.File.ReadAllBytes(filePath);


    regards,

    George

    +1
  • Bechir Bejaoui
    +1
    Suppose that you have data stored in  a dat file for the image
     byte[]ImageData = Convert.FromBase64String(stringContent);
     MemoryStream oStream = new MemoryStream(ImageData);
     Image myImage = Image.FromStream(oStream);
    +1