can not save image as raw format after being croped or resized

2 posts, 0 answers
  1. Mamad
    Mamad avatar
    1 posts
    Member since:
    May 2013

    Posted 20 May 2013 Link to this post

    Hi
    I have a problem using radimageeditor.when i crop or resize an image and save it using onimagesaving file size gets too larger than expected.how can i fix that.



     private void GenerateThumbnails(System.Drawing.Image image,string sourcePath, string thumbname, string thumbname2)
        {

        
            using (image)
            {
                var thumbnailImg = new System.Drawing.Bitmap(245, 200);
                var thumbGraph = System.Drawing.Graphics.FromImage(thumbnailImg);
                thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
                thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
                thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
                //thumbGraph.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed;
                var imageRectangle = new System.Drawing.Rectangle(0, 0, 245, 200);
                thumbGraph.DrawImage(image, imageRectangle);

                thumbnailImg.Save(thumbname, image.RawFormat);


               thumbnailImg = new System.Drawing.Bitmap(70, 70);
              thumbGraph = System.Drawing.Graphics.FromImage(thumbnailImg);
              imageRectangle = new System.Drawing.Rectangle(0, 0, 70, 70);
              thumbGraph.DrawImage(image, imageRectangle);


                thumbnailImg.Save(thumbname2, image.RawFormat);

            }
        }


     protected void RadImageEditor1_OnImageSaving(object sender, Telerik.Web.UI.ImageEditorSavingEventArgs e)
        {
            string filename = Server.MapPath(folderPath + e.FileName + ".jpg");

            string thumbname = Server.MapPath(folderPath + e.FileName + "_thumb.jpg");

            string thumbname2 = Server.MapPath(folderPath + e.FileName + "_thumb2.jpg");

            System.Drawing.Image img = e.Image.Image;

         
            GenerateThumbnails(img,filename, thumbname, thumbname2);
            e.Cancel = true;
        }
  2. Niko
    Admin
    Niko avatar
    387 posts

    Posted 23 May 2013 Link to this post

    Hi,

    In the provided example code I see that you cancel the OnImageSaving event. At the same time there is only code that generates 2 thumbnails, but does not save the main image. Since you cancel the event, it should expected that the image saving to be handled in the event handler, because the ImageEditor itself will not save the image. This may be the reason why the image has larger size than expected, i.e. the original size.
    You have 2 options here - one is to not cancel the event and let the ImageEditor store the changes in the image you are editing, the second option is to handle the saving of the image in the OnImageSaving event handler.

    Hope this helps.

    Regards,
    Niko
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top