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

How to Reduce loaded image pixel size in RadAsyncUpload.

2 Answers 254 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sairam
Top achievements
Rank 1
Sairam asked on 31 May 2013, 09:44 AM
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 Answers, 1 is accepted

Sort by
0
Sairam
Top achievements
Rank 1
answered on 05 Jun 2013, 06:15 AM
It directly Not possible....but using    img.thumbnail()  property is possible....complete solution is  available   in codeproject .com.....serach
image resize ..sairam pamid post
0
Hristo Valyavicharski
Telerik team
answered on 05 Jun 2013, 07:14 AM
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.
Tags
General Discussions
Asked by
Sairam
Top achievements
Rank 1
Answers by
Sairam
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Share this question
or