I was using the following code to enter an image url at TextBox1 and display it in PictureBox1.Everything worked.

But suddenly the displayed image quality is lower than the original link. I've tried PictureBox1.Load(TextBox1.Text) and changing SizeMode still the same result.

Imports System.Net
    Public Class Form1
        Dim client As WebClient
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            client = New WebClient()

            Dim ImageInBytes() As Byte = client.DownloadData(TextBox1.Text)

            Dim ImageStream As New IO.MemoryStream(ImageInBytes)

            PictureBox1.Image = New System.Drawing.Bitmap(ImageStream)

         End Sub
        End Class

I'm using
Microsoft Visual Studio 2010 Version 10.0.30319.1 RTMRel Microsoft .NET Framework Version 4.0.30319 RTMRel

How can I get the image to display without the quality loss?

Dani AI

Generated

Two things usually make a remote image “look bad” in a WinForms PictureBox: either the bytes you actually downloaded are a different, lower‑quality image (CDN/proxy/thumbs/recompression), or the image is being poorly resampled when the control stretches it. was right to look at network/size, and the fact that a different connection fixed it for strongly points at an on‑path optimizer or CDN variant rather than raw TCP packet corruption (TCP retransmits lost packets, so you normally don’t get silently degraded images).

Quick, practical checks:

  • Open the exact image URL in a desktop browser and inspect the final URL (look for redirects or query params like ?w=...). If the browser gets a smaller variant, the server/CDN is serving it.
  • Save the bytes your app downloads to disk and open that file in an external image viewer. If the saved file is already low‑res, the problem is server/proxy side. If the saved file is fine but PictureBox shows low quality, the issue is clientside resampling.
  • Use a tool (Fiddler, curl -I) to view response headers (Content-Length, Content-Encoding, redirects). Some ISPs or mobile proxies re-encode images to save bandwidth.

If client-side scaling is the culprit, resize with high-quality interpolation before assigning to the PictureBox. Example VB.NET helper (create and draw a high-quality resized bitmap):

Function ResizeHighQuality(src As Image, targetW As Integer, targetH As Integer) As Bitmap
    Dim dest As New Bitmap(targetW, targetH)
    dest.SetResolution(src.HorizontalResolution, src.VerticalResolution)
    Using g = Graphics.FromImage(dest)
        g.CompositingQuality = CompositingQuality.HighQuality
        g.InterpolationMode = InterpolationMode.HighQualityBicubic
        g.SmoothingMode = SmoothingMode.HighQuality
        g.PixelOffsetMode = PixelOffsetMode.HighQuality
        g.DrawImage(src, 0, 0, targetW, targetH)
    End Using
    Return dest
End Function

If the server is serving a smaller image, request the original URL (or set a desktop User‑Agent) or fetch from a different host. If the PictureBox must scale, prefer pre‑resampling with the routine above rather than relying on PictureBox’s stretch modes.

Recommended Answers

All 2 Replies

One thing to take into consideration in packet loss /size of image.

If there is a large amount of packet loss between you and the site - the quality will suffer greatly.

If the size of your picturebox is smaller/larger than the original image there will be stretching or pinching. This causes pixelation.

One thing to take into consideration in packet loss /size of image.

If there is a large amount of packet loss between you and the site - the quality will suffer greatly.

Yep,that's the problem. I tested it using a different internet connection and it worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.