This is a migrated thread and some comments may be shown as answers.

RadImageGallery Thumbnail URL

2 Answers 122 Views
ImageGallery
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 23 Sep 2019, 05:36 PM

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 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 23 Sep 2019, 05:37 PM
returnImage.ImageUrl works perfectly fine.
returnImage.ThumbnailUrl does not.
0
Richard
Top achievements
Rank 1
answered on 23 Sep 2019, 07:10 PM
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.
Tags
ImageGallery
Asked by
Richard
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Share this question
or