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

Keeping the image format on thumbnail

1 Answer 22 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Roy Halvorsen
Top achievements
Rank 1
Roy Halvorsen asked on 14 Nov 2012, 10:27 AM
All thumbnails are saved in .png format. How can I keep the original image's format on thumbnails? If I edit on a .jpg image, I want the thumbnail also to be a .jpg image.
This is what I have tried with no success:
protected void RadImageEditor1_ImageSaving(object sender, ImageEditorSavingEventArgs args)
{
    var thumbImage = args.Image.Clone();
    var pathToThumbs = "~/Filarkiv/thumb/";
    thumbImage.Resize(96, 96);
 
    var ms = new MemoryStream();
    thumbImage.Image.Save(ms, args.Image.RawFormat);
    File.WriteAllBytes(String.Format("{0}{1}.{2}", MapPath(pathToThumbs), args.FileName, args.Image.Format), byte[])ms.ToArray());
}


Roy

1 Answer, 1 is accepted

Sort by
0
Roy Halvorsen
Top achievements
Rank 1
answered on 14 Nov 2012, 02:02 PM
Forget this. The solution was simple:

var fileformat = Path.GetExtension(RImgEditor.ImageUrl);
 
var thumbImage = args.Image.Clone();
var pathToThumbs = "~/Filarkiv/thumb/";
thumbImage.Resize(96, 96);
 
var ms = new MemoryStream();
thumbImage.Image.Save(ms, args.Image.RawFormat);
File.WriteAllBytes(String.Format("{0}{1}{2}", MapPath(pathToThumbs), args.FileName, fileformat), (byte[])ms.ToArray());

Roy
Tags
ImageEditor
Asked by
Roy Halvorsen
Top achievements
Rank 1
Answers by
Roy Halvorsen
Top achievements
Rank 1
Share this question
or