Keeping the image format on thumbnail

2 posts, 0 answers
  1. Roy Halvorsen
    Roy Halvorsen avatar
    83 posts
    Member since:
    Oct 2008

    Posted 14 Nov 2012 Link to this post

    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
  2. Roy Halvorsen
    Roy Halvorsen avatar
    83 posts
    Member since:
    Oct 2008

    Posted 14 Nov 2012 Link to this post

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