An exception of type 'System.UriFormatException' occurred in System.dll but was not handled in user code Additional information: Invalid URI: The Uri string is too long.

This happened to me when I was resizing an image, and did not put the image type when converting it to a byte array and then converting to base64.

Also was previously trying all sorts of ways to display this one image from the database.  Turns out some person was directly dropping the image into the column through Access.  Weirdly enough that way works in Crystal Reports, but I cannot get it to display on a web page no matter what I tried.  Tried for something like 12 hours or so over 2-3 days, so there is something odd with that.

Should look something like these.

imgRepPic.ImageUrl = "data:image/jpeg;base64," & Convert.ToBase64String((DirectCast(dtPic(0)("repPic"), Byte())))

.....
Dim imgTemp As Image = ScaleImage(System.Drawing.Image.FromStream(stream), 100)
  imgRepPicProportional.ImageUrl = "data:image/jpeg;base64," & Convert.ToBase64String((ImageToByteArray(imgTemp)))

....


  Public Shared Function ScaleImage(curImage As System.Drawing.Image, maxHeight As Integer) As System.Drawing.Image
        Dim ratio = CDbl(maxHeight) / curImage.Height

        Dim newWidth = CInt(curImage.Width * ratio)
        Dim newHeight = CInt(curImage.Height * ratio)

        Dim newImage As New Bitmap(100, newHeight)
        Using g = Graphics.FromImage(newImage)
            g.DrawImage(curImage, 0, 0, newWidth, newHeight)
        End Using
        Return newImage
    End Function

Public Function ImageToByteArray(imageIn As System.Drawing.Image) As Byte()
        Dim ms As New MemoryStream()
        imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
        Return ms.ToArray()
    End Function

Comments

Popular posts from this blog

Asp.net Publishing Broke Site - "App_WebReferences is not allowed because the application is precompiled"

Telerik - Custom Group Footers In RadGrid

Bootstrap Modal Popup is Grayed Out