Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9128287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:28:48+00:00 2026-06-17T07:28:48+00:00

I want to convert a PNG image found in a path to base64 for

  • 0

I want to convert a PNG image found in a path to base64 for a html page in Windows phone7.1.How can it be done?

        Stream imgStream;
        imgStream =   Assembly.GetExecutingAssembly().GetManifestResourceStream("NewUIChanges.Htmlfile.round1.png");
        byte[] data = new byte[(int)imgStream.Length];
        int offset = 0;
        while (offset < data.Length)
        {
            int bytesRead = imgStream.Read(data, offset, data.Length - offset);
            if (bytesRead <= 0)
            {
                throw new EndOfStreamException("Stream wasn't as long as it claimed");
            }
            offset += bytesRead;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:28:49+00:00Added an answer on June 17, 2026 at 7:28 am

    The fact that it’s a PNG image is actually irrelevant – all you need to know is that you’ve got some bytes that you need to convert into base64.

    Read the data from a stream into a byte array, and then use Convert.ToBase64String. Reading a byte array from a stream can be slightly fiddly, depending on whether the stream advertises its length or not. If it does, you can use:

    byte[] data = new byte[(int) stream.Length];
    int offset = 0;
    while (offset < data.Length)
    {
        int bytesRead = stream.Read(data, offset, data.Length - offset);
        if (bytesRead <= 0)
        {
            throw new EndOfStreamException("Stream wasn't as long as it claimed");
        }
        offset += bytesRead;
    }
    

    If it doesn’t, the simplest approach is probably to copy it to a MemoryStream:

    using (MemoryStream ms = new MemoryStream())
    {
        byte[] buffer = new byte[8 * 1024];
        int bytesRead;
        while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
        {
            ms.Write(buffer, 0, bytesRead);
        }
        return ms.ToByteArray();
    }
    

    So once you’ve used either of those bits of code (or anything else suitable) to get a byte array, just use Convert.ToBase64String and you’re away.

    There are probably streaming solutions which will avoid ever having the whole byte array in memory – e.g. building up a StringBuilder of base64 data as it goes – but they would be more complicated. Unless you’re going to deal with very large files, I’d stick with the above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image (in .png format), and I want this picture to convert
I want to convert a alpha transparent png image to palette based png image.
I want to convert the input 24 bit PNG image to 8 bit, I
I am having Image data in base64 format, I want to convert this base64
I to want convert PDF pages into an image (PNG,JPEG/JPG or GIF). I want
I want to convert a xaml canvas to a png image using c#. I
How to convert imagedata into base64 my code is: UIImage *image = [UIImage imageNamed:@BombTense.png];
I found this command Resize an image with improved quality: $ convert input.png -colorspace
I want to use ffmpeg to convert swf to png ,and I can't extract
I want to convert a jpg file to png, but when I run this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.