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

  • Home
  • SEARCH
  • 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 84989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:01:07+00:00 2026-05-10T22:01:07+00:00

I’ve download an image from the Internet and converted to a String (This is

  • 0

I’ve download an image from the Internet and converted to a String (This is not changeable)

Dim Request As System.Net.WebRequest = _   System.Net.WebRequest.Create( _   'http://www.google.com/images/nav_logo.png')  Dim WebResponse As System.Net.HttpWebResponse = _   DirectCast(Request.GetResponse(), System.Net.HttpWebResponse)  Dim Stream As New System.IO.StreamReader( _   WebResponse.GetResponseStream, System.Text.Encoding.UTF8)  Dim Text as String = Stream.ReadToEnd 

How can I convert the String back to the Stream?

So I can use that stream to get the image.

Like this:

Dim Image As New Drawing.Bitmap(WebResponse.GetResponseStream) 

But now I’ve only the Text String, so I need something like this:

Dim Stream as Stream = ReadToStream(Text, System.Text.Encoding.UTF8) Dim Image As New Drawing.Bitmap(Stream) 

EDIT:

This engine was primarily used for downloading web pages but I’m trying to use it for downloading images too. The format of the string is UTF8, as given in the example code…

I’ve tried to use the MemoryStream(Encoding.UTF8.GetBytes(Text)), but I got this error when loading the stream to the image:

A generic error occurred in GDI+.

What gets lost in the conversions?

  • 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. 2026-05-10T22:01:07+00:00Added an answer on May 10, 2026 at 10:01 pm

    Why have you converted binary (image) data to a string? This makes no sense… unless you are using base-64?

    Anyway, to reverse what you have done, you could try using new MemoryStream(Encoding.UTF8.GetBytes(text))?

    This will create a new MemoryStream primed with the string (via UTF8). Personally, I doubt it will work – you are going to run into a lot of encoding issues treating raw binary as UTF8 data… I expect either the read or write (or both) to throw an exception.

    (edit)

    I should add that to work with base-64, simply get the data as a byte[], then call Convert.ToBase64String(...); and to get back the array, just use Convert.FromBase64String(...).


    Re your edit, this is precisely what I tried to warn about above… in .NET, a string is not just a byte[], so you can’t simply fill it with binary image data. A lot of the data simply won’t make sense to the encoding, so might be quietly dropped (or an exception thrown).

    To handle raw binary (such as images) as strings, you need to use base-64 encoding; this adds size, however. Note that WebClient might make this simpler, as it exposes byte[] functionality directly:

    using(WebClient wc = new WebClient()) {     byte[] raw = wc.DownloadData('http://www.google.com/images/nav_logo.png')     //... } 

    Anyway, using a standard Stream approach, here’s how to encode and decode the base-64:

            // ENCODE         // where 's' is our original stream         string base64;         // first I need the data as a byte[]; I'll use         // MemoryStream, as a convenience; if you already         // have the byte[] you can skip this         using (MemoryStream ms = new MemoryStream())         {             byte[] buffer = new byte[1024];             int bytesRead;             while ((bytesRead = s.Read(buffer, 0, buffer.Length)) > 0)             {                 ms.Write(buffer, 0, bytesRead);             }             base64 = Convert.ToBase64String(ms.GetBuffer(), 0, (int) ms.Length);         }          // DECODE         byte[] raw = Convert.FromBase64String(base64);         using (MemoryStream decoded = new MemoryStream(raw))         {             // 'decoded' now primed with the binary         } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 234k
  • Answers 234k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I found my answer, not an upgrade related issue. This… May 13, 2026 at 5:54 am
  • Editorial Team
    Editorial Team added an answer Have a look at this. If I misunderstood, please let… May 13, 2026 at 5:54 am
  • Editorial Team
    Editorial Team added an answer http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/ Then you can explode the path and compare it… May 13, 2026 at 5:54 am

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.