Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
flluidmedia  
#1 Posted : Monday, June 21, 2004 4:22:00 AM(UTC)
flluidmedia

Rank: Member

Groups: Member
Joined: 4/27/2004(UTC)
Posts: 40

I am trying to read some image files from the internet into my application. Previously, I was using the GDI+ Image class with the following code:

Code:
using( WebClient wc = new WebClient() )
{
	Stream strm = null;
				
	try
	{
		strm = wc.OpenRead(url);
		return Image.FromStream(strm); 
	}
	catch
	{
		return null;
	}
	finally
	{
		if( strm != null )
			strm.Close();
	}
					
}

But using this code with an Aurigma Bitmap instead doesnt work since the WebClient doesnt use the IStream interface.

I found the following code in the help for aurigma:

Code:
Private Sub MenuLoadingURL_Click()
    'You should add reference to Microsoft XML in order to use early binding
    'Dim xmlHTTP As New xmlHTTP
    
    Dim xmlHTTP
    On Error Resume Next
    Set xmlHTTP = CreateObject("Msxml2.XMLHTTP")
    If Err.Number <> 0 Then
        MsgBox "MSXML should be installed on computer to load from url."
        Exit Sub
    End If
    Err.Clear
    On Error GoTo 0
    
    Dim strImageURL As String
    strImageURL = InputBox("Please type image URL.", "Loading Image from URL", _
        "http://www.aurigma.com/images/primary/primary1.jpg")
    
    On Error GoTo Catch
    
    'Download file from URL
    xmlHTTP.open "GET", strImageURL, False
    xmlHTTP.send
    
    'Load image from stream
    BitmapViewer1.Bitmap.LoadFromStream xmlHTTP.responseStream
    
    Exit Sub
Catch:
    MsgBox "Error arrised during loading image."
End Sub

But I have no idea how to convert this one over to C#!! I've been through the objects that I have access to under .NET but none of them seem to be what I need.

Has anyone done this?

Thanks,

Brian

Fluid Media

Edited by user Monday, December 24, 2007 4:23:58 PM(UTC)  | Reason: Not specified

Andrew  
#2 Posted : Monday, June 21, 2004 12:55:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
The problem is that Graphics Mill expects COM stream (which is represented as IStream interface in COM applications). .NET stream is not compatible with COM streams as it does not provide IStream interface. That's why you cannot directly pass Stream object to LoadFromStream/SaveToStream method of GraphicsMill.Bitmap.

There are several approaches how to solve this problem:

  1. Use GDI+ bitmap as you done it before. Obviously has a number of drawbacks, first of all unnecessary overhead.

  2. Copy stream to array first, then use LoadFromMemory method of GraphicsMill.Bitmap. It is much simplier, but there is still temporary memory overhead.

  3. Implement a class which incapsulates stream, and implements IStream interface (you need to inherit it from UCOMIStream interface in .NET). You just store .NET stream object as a private member of this class and call its methods in implementation of UCOMIStream.

  4. Use some COM class which can load file from internet and give it as IStream. The example of this you posted above. Certainly you should not use any .NET analogues of this class, because even if they provide necessary functionality, they return .NET-style streams, not IStream. That's why you should import COM object MSXML in the same way as Graphics Mill. After you do that, I think you won't have any problems with adapting this code to C#. But if something will go wrong, please feel free to let me know.

Fedor  
#3 Posted : Sunday, January 2, 2005 9:15:00 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
We have released Graphics Mill 3.0 for .NET with help of which loading from url can be implemented easy:

VB

Code:
Dim webClient As New System.Net.WebClient
Dim stream As System.IO.Stream = webClient.OpenRead( _
    "http://www.aurigma.com/images/Rotated.png")
Dim bitmap As New Aurigma.GraphicsMill.Bitmap(stream)
stream.Close()
webClient.Dispose()

C#

Code:
Aurigma.GraphicsMill.Bitmap bitmap = null;
using (System.Net.WebClient webClient = new System.Net.WebClient())
{
    using (System.IO.Stream stream = webClient.OpenRead( 
               @"http://www.aurigma.com/images/Rotated.png"))
    {
        bitmap = new Aurigma.GraphicsMill.Bitmap(stream);
    }
}

You can read more on Graphics Mill for .NET forum.

Edited by user Monday, December 24, 2007 4:24:38 PM(UTC)  | Reason: Not specified

Best regards,

Fedor Skvortsov

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.