How to Reduce loaded image pixel size in RadAsyncUpload.

3 posts, 0 answers
  1. Sairam
    Sairam avatar
    56 posts
    Member since:
    May 2013

    Posted 31 May 2013 Link to this post

    Hello telerik team,

    I am rad async Upload control...I loaded image  but, I want to reduce pixel size ,i am uploaded picture  how much width and height must and should ..I want to store image in the following pixel sizes "100 width *30 height " ....how reduce pixel size...provide some snippet to me.

      <telerik:RadAsyncUpload runat="server" ID="ImgImages2" AllowedFileExtensions=".jpg,.jpeg,.png,.gif"
                                MaxFileInputsCount="1" Skin="Outlook" Width="350px" PostbackTriggers="PerformInsertButton" />
    Insert()

      byte[] fileData;
            if (ImgImages.UploadedFiles.Count > 0)
            {
                UploadedFile file = ImgImages.UploadedFiles[0];
                fileData = new byte[file.InputStream.Length];
                string ImgFileName1 = ImgImages.UploadedFiles[0].FileName;
                file.InputStream.Read(fileData, 0, (int)file.InputStream.Length);
                if (fileData.Length > 1048576)
                {
                    RadWindowManager1.RadAlert("The length of the uploaded file must be less than 1 MB", 300, 100, "Check SetUp Signature", null);
                    return;
                }
                //string ImgFileName = ImgImages.UploadedFiles[0].FileName;
                oCheck.ImgFileName = ImgFileName1;
                oCheck.Signature = fileData;

            }

    How reduce pixel size provide some snippet. and how to covert   "radasyncfile.upload[0].file" to "Image "  fro the above one.
  2. Sairam
    Sairam avatar
    56 posts
    Member since:
    May 2013

    Posted 05 Jun 2013 Link to this post

    It directly Not possible....but using    img.thumbnail()  property is possible....complete solution is  available   in codeproject .com.....serach
    image resize ..sairam pamid post
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 05 Jun 2013 Link to this post

    Hi Sairam,

    This online demo shows the same functionality. Code you need is in Handler.ashx.cs. Here is a code snippet:
    public Bitmap ResizeImage(Stream stream)
       {
           Image originalImage = Bitmap.FromStream(stream);
     
           int height = 500;
           int width = 500;
     
           double ratio = Math.Min(originalImage.Width, originalImage.Height) / (double)Math.Max(originalImage.Width, originalImage.Height);
     
           if (originalImage.Width > originalImage.Height)
           {
               height = Convert.ToInt32(height * ratio);
           }
           else
           {
               width = Convert.ToInt32(width * ratio);
           }
     
           Bitmap scaledImage = new Bitmap(width, height);
     
           using (Graphics g = Graphics.FromImage(scaledImage))
           {
               g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
               g.DrawImage(originalImage, 0, 0, width, height);
     
               return scaledImage;
           }
     
       }

    Regards,
    Hristo Valyavicharski
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top