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

About An EditableImage Problem

2 Answers 84 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Erkan Şahan
Top achievements
Rank 1
Erkan Şahan asked on 30 Jan 2012, 04:21 PM
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 Answers, 1 is accepted

Sort by
0
Niko
Telerik team
answered on 01 Feb 2012, 05:38 PM
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
0
Erkan Şahan
Top achievements
Rank 1
answered on 09 Feb 2012, 02:23 PM
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
Tags
ImageEditor
Asked by
Erkan Şahan
Top achievements
Rank 1
Answers by
Niko
Telerik team
Erkan Şahan
Top achievements
Rank 1
Share this question
or