About An EditableImage Problem

3 posts, 0 answers
  1. Erkan Şahan
    Erkan Şahan avatar
    4 posts
    Member since:
    Oct 2009

    Posted 30 Jan 2012 Link to this post

    Hi,

    I have an issue about EditableImage. I'm trying to resize images but i get some exceptions like "Image stream seems to be causing issues" or "The source of the image seems to be invalid".

    It doesn't throw exceptions always. Only some images couse the error. For example I attached two image. Org is the original image. And the other is edited image.

    Org gives error. When i edit in photoshop and resize width to 750px it works.

    My code is here :

    protected void btnAddImage_Click(object sender, System.EventArgs e)
            {
                Stream StreamImage = flImage.PostedFile.InputStream;
                MemoryStream ms = new MemoryStream();
     
                byte[] imgData = new byte[StreamImage.Length];
                StreamImage.Read(imgData, 0, imgData.Length);
     
                ms.Write(imgData, 0, imgData.Length);
     
                SaveImage(ms, "g_" + PhotoID.ToString(), 610, 610);
            }
     
            void SaveImage(MemoryStream ms, string FileName, int Width, int Height)
            {
                try
                {
                    EditableImage image = new EditableImage(ms);
                    decimal oran = 0;
                    Size s;
                    if (!(Width > image.Width && Height > image.Height))
                    {
                        if ((Width / Convert.ToDecimal(image.Width)) > (Height / Convert.ToDecimal(image.Height)))
                        {
                            //Height
                            oran = Height / Convert.ToDecimal(image.Height);
                            s = new Size(Convert.ToInt32(oran * image.Width), Convert.ToInt32(oran * image.Height));
                        }
                        else
                        {
                            //Width
                            oran = Width / Convert.ToDecimal(image.Width);
                            s = new Size(Convert.ToInt32(oran * image.Width), Convert.ToInt32(oran * image.Height));
                        }
                        image.Resize(s);
                    }
     
                    image.Image.Save(Server.MapPath(Settings["FolderPath"].ToString() + FileName + ".jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

    Thanks for your help.
  2. Niko
    Admin
    Niko avatar
    387 posts

    Posted 01 Feb 2012 Link to this post

    Hello Erkan,

    Unfortunately I wasn't able to reproduce the issue on my side using the original image. I was using the attached page to upload and edit the image in the code behind. Could you, please, try this page and see if this works on your side as well?

    All the best,
    Niko
    the Telerik team
    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
  4. Erkan Şahan
    Erkan Şahan avatar
    4 posts
    Member since:
    Oct 2009

    Posted 09 Feb 2012 Link to this post

    Hi Niko,

    Thx for your reply. I implemented the code you sent.

    As i said before, the stuation is not stable. So we can't get the error now. If it gives error, i will write again.

    Thx again.
    Erkan
Back to Top