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

ImageUrl on another server . . .

8 Answers 207 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Geoff
Top achievements
Rank 1
Geoff asked on 09 Jul 2012, 08:12 PM
I saw this older thread http://www.telerik.com/community/forums/aspnet-ajax/image-editor/imageurl-http.aspx and it's conclusion is that you can not use the ImageUrl unless it is localized inside a folder that the application has access to.

Has this since been changed? This is quite an inconvenience as most of the images I will be using are hosted on a separate media server.

I'm getting my URL off of a data table, which has all of the images already loaded.

public DataTable ProductDetailsDataTable
{
    get
    {
        return _productDetailsDataTable;
    }
 
    set
    {
        _productDetailsDataTable = value;
 
        //add code to read data from table and do something with it
        DataRow dr = _productDetailsDataTable.Rows[0];
 
        RadImageEditor1.ImageUrl = dr["Image1Url"].ToString();
         
 
    }
}

8 Answers, 1 is accepted

Sort by
0
Niko
Telerik team
answered on 10 Jul 2012, 11:49 AM
Hi Geoff,

If there is a need for an alternative way of loading images there are two ways to do a custom image loading. First is to use the ImageLoading/ImageSaving events - http://www.telerik.com/help/aspnet-ajax/imageeditor-server-side-events.html.
Second option is to use a custom content provider - http://demos.telerik.com/aspnet-ajax/imageeditor/examples/customcontentprovider/defaultcs.aspx.

Any of these options is perfectly valid and choosing any of them is only a matter of preference.

Hope this helps.

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
Geoff
Top achievements
Rank 1
answered on 10 Jul 2012, 04:08 PM
Thanks for your reply.

I don't follow how the 2 options you showed me will help with what I want to do. I simply want to load in a url that exists on, pulling the string text from a datatable, and then point the image editor to it.

I am only using the image editor for the zoom in/zoom out/ refresh, so not true editing will be done to any image.

Is there another rad control out there that you would suggest to accomplish what I'm wanting to do?
0
Accepted
Niko
Telerik team
answered on 11 Jul 2012, 09:46 AM
Hello Geoff,

Please, find attached the approach that you can use to loading images from an URL. Similar approach could be taken when loading images from the local network.

Kind regards,
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
Geoff
Top achievements
Rank 1
answered on 16 Jul 2012, 07:28 PM
Niko,

This was a big help and with a little bit of tweaking was able to get it to do what I wanted.

Thanks so much!
0
Martin Roussel
Top achievements
Rank 1
answered on 07 Aug 2012, 08:08 PM
Hi, ive managed to use to provided zip to do the same with an image located on our network, however, im having problem closing the stream which will cause problem if not fixed. Here's the code:

public void RadImageEditor1_OnImageLoading(object sender, Telerik.Web.UI.ImageEditorLoadingEventArgs args)
        {
            FileStream fs = null;
            try
            {
                    var imageUrl = ((RadImageEditor)sender).ImageUrl;
                    var webImage = LoadImageFromNetwork(ref fs, imageUrl);
                    args.Image = new EditableImage(webImage);
                    args.Cancel = true;
            }
            catch (WebException)
            {
                args.Cancel = false;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                    fs.Dispose();
                    fs = null;
                }
            }
 
        }
 
private System.Drawing.Image LoadImageFromNetwork(ref FileStream fs, string strPath)
{
    fs = new FileStream(strPath, FileMode.Open, FileAccess.Read);
 
    return new Bitmap(fs));
}

It works only if I remove the "finally" statement from the code (looks like I must not close the stream) but I know i have to close it somewhere.

Anyone can help with this please?
0
Niko
Telerik team
answered on 09 Aug 2012, 10:45 AM
Hello Geoff,

Closing the FileStream should not be an issue, unless you are using a MemoryStream within the LoadImageFromNetwork method. There is a known issue with GDI+(the library that is used to edit the image), where the memory stream used by the image should not be closed until the image has been saved.

For more information, please, refer to the following general articles on the topic - http://stackoverflow.com/questions/1053052/a-generic-error-occurred-in-gdi-jpeg-image-to-memorystream and http://stackoverflow.com/questions/336387/image-save-throws-a-gdi-exception-because-the-memory-stream-is-closed.

Here is a sample code that uses DB as an image source. The same should work with any binary source:
protected void RadImageEditor1_ImageLoading(object sender, Telerik.Web.UI.ImageEditorLoadingEventArgs args)
{
    using (dal d = new dal("dB"))
    {
        byte[] imgData = (byte[])d.ExecuteScalar("SELECT Data FROM Images WHERE ID = @id", new SqlParameter("id", imageId));
   
        Stream s = new MemoryStream();
        s.Write(imgData, 0, imgData.Length);
        args.Image = new EditableImage(s);
   
        args.Cancel = true;
    }
}

Hope this helps.

Greetings,
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
Martin Roussel
Top achievements
Rank 1
answered on 09 Aug 2012, 12:18 PM
Thanks for the reply. Ive managed to fix it this way:

private System.Drawing.Image LoadImageFromNetwork(string strPath)
        {
                using (FileStream fs = File.OpenRead(strPath))
                {
                    MemoryStream memStream = new MemoryStream();
                    memStream.SetLength(fs.Length);
                    fs.Read(memStream.GetBuffer(), 0, (int)fs.Length);
                    return new Bitmap(memStream);
                }
 
         }

The only thing, im wondering if I have to Close/Dispose "memStream" at a certain point (or it get disposed by itself?). If i do it at the end of "OnImageLoading", I get a blank image.






Martin
0
Niko
Telerik team
answered on 13 Aug 2012, 08:43 AM
Hello Geoff,

It's great that you managed to come up with a working approach. As far as the memory stream is concerned, the System.Drawing.Image object should take care of managing it. Within our graphics core implementation we do additional cleaning up just to make sure everything is properly disposed. Therefore you should not worry about disposing the memory stream in the OnImageLoading event handler.

Hope this helps.

Greetings,
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.
Tags
ImageEditor
Asked by
Geoff
Top achievements
Rank 1
Answers by
Niko
Telerik team
Geoff
Top achievements
Rank 1
Martin Roussel
Top achievements
Rank 1
Share this question
or