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

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

1 Answer 56 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Mamad
Top achievements
Rank 1
Mamad asked on 20 May 2013, 02:38 PM
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;
    }

1 Answer, 1 is accepted

Sort by
0
Niko
Telerik team
answered on 23 May 2013, 12:32 PM
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.
Tags
ImageEditor
Asked by
Mamad
Top achievements
Rank 1
Answers by
Niko
Telerik team
Share this question
or