Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post

    Image rotate almost working

    Found this script online, sort of helps me with my issue but ran into a wall.

    Here is the code
    Code:
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    using System.Drawing;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Button1_Click(object sender, EventArgs e)
        {
            //get the path to the image
            string path = Server.MapPath(Image1.ImageUrl);
    
            //create an image object from the image in that path
            System.Drawing.Image img = System.Drawing.Image.FromFile(path);
    
            //rotate the image
            img.RotateFlip(RotateFlipType.Rotate90FlipXY);
    
            //save the image out to the file
            img.Save(path);
    
            //release image file
            img.Dispose();
        }
    }
    And the error:
    Code:
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
    
    Source Error: 
    
    
    Line 21: 
    Line 22:         //save the image out to the file
    Line 23:         img.Save(path);
    Line 24: 
    Line 25:         //release image file
    And yeah the "path" string is correct and points to the original file.

  • #2
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    anyone?

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,166
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Heard of documentation?

    http://msdn.microsoft.com/en-us/library/ktx83wah.aspx

    From that page:
    Exceptions
    ExternalException :
    The image was saved with the wrong image format.
    -or-
    The image was saved to the same file it was created from.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-16-2013)

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,166
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    As a guess, if you want to save it back to the same file, you may need to delete the file after loading it.

    Or you could rename it to a dummy name, load from that dummy name, and then save it back to the original name.

    But I tell you again: This forum is not the best place to get ASP.NET answers. Try www.asp.net forums.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-16-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •