RadImageGallery Thumbnail URL

3 posts, 0 answers
  1. Richard
    Richard avatar
    4 posts
    Member since:
    Aug 2012

    Posted 23 Sep Link to this post

    I am converting an old application that stores its images as base64strings in a SQL Server database.

    I am trying to add the images to the gallery. Pointing the ImageURL to a base64 string works fine, but not the ThumbnailURL.

            public static string ImageToBase64(System.Drawing.Image image, System.Drawing.Imaging.ImageFormat format)

            {
                string returnString = "";
                System.IO.MemoryStream ms = new MemoryStream();

                image.Save(ms, format);
                byte[] imageBytes = ms.ToArray();
                returnString = "data:image;base64," + Convert.ToBase64String(imageBytes);

                return returnString;
            }

            public static Telerik.Web.UI.ImageGalleryItem ImageBase64(byte[] BlobData, string ImageTitle)
            {
                Telerik.Web.UI.ImageGalleryItem returnImage = new Telerik.Web.UI.ImageGalleryItem();

                System.Drawing.Image img = null;
                System.IO.MemoryStream mem = new MemoryStream();
                mem.Write(BlobData, 0, BlobData.Length);
                mem.Seek(0, SeekOrigin.Begin);

                img = System.Drawing.Image.FromStream(mem);

                returnImage.Title = ImageTitle;
                returnImage.ThumbnailUrl = ImageToBase64(SizedImage(img, 100, 75), System.Drawing.Imaging.ImageFormat.Jpeg);
                returnImage.ImageUrl =     ImageToBase64(SizedImage(img, 800, 600), System.Drawing.Imaging.ImageFormat.Jpeg);
                return returnImage;
            }

            returnImage.ImageUrl works perfectly fine.

     


            public static System.Drawing.Bitmap SizedImage(System.Drawing.Image img, int dispWidth, int dispHeight)
            {
                double scale = 1.0, hScale = 1.0;
                double imgWidth = img.Width;
                double imgHeight = img.Height;

                if (imgWidth > dispWidth)
                    scale = dispWidth / imgWidth;
                if (imgHeight > dispHeight)
                    hScale = dispHeight / imgHeight;
                if (hScale < scale)
                    scale = hScale;

                int imgw = Convert.ToInt32(imgWidth * scale);
                int imgh = Convert.ToInt32(imgHeight * scale);

                return new System.Drawing.Bitmap(img, imgw, imgh);
            }

  2. Richard
    Richard avatar
    4 posts
    Member since:
    Aug 2012

    Posted 23 Sep Link to this post

    returnImage.ImageUrl works perfectly fine.
    returnImage.ThumbnailUrl does not.
  3. Richard
    Richard avatar
    4 posts
    Member since:
    Aug 2012

    Posted 23 Sep Link to this post

    Have determined that the issue is that thumbnails are not preserved after postback.

    If the images are loaded at every postback, the thumbnails load fine. If the images are not re-loaded at every postback, the images are still displayed, but the thumbnails are lost.
Back to Top