WebClient & graphic objects?

  • Thread starter Thread starter Phil Crosland
  • Start date Start date
P

Phil Crosland

I want to access online graphics for a networked application I am writing &
am having trouble using the WebClient for this. Basically I want the users
to be able to enter an URI to a file either on their local machien or on the
web which they can then use as their icon. I wasnt planning on saving the
file locally - just having in memory. I tried downloading into a byte array
but can find no way of converting that into a graphics object.

Any help on this would be appreciated.

thanks in advance
Phil Crosland
 
string remoteUri = "http://www.contoso.com/library/homepage/images/";

string fileName = "ms-banner.gif", myStringWebResource = null;

// Create a new WebClient instance.

WebClient myWebClient = new WebClient();

// Concatenate the domain with the Web resource filename.

myStringWebResource = remoteUri + fileName;

myWebClient.DownloadFile(myStringWebResource,fileName)



download locally, then use Image.FromFile
 
thanks - ya thats pretty much what I have now - I was hoping to be able to
use the stream though directly into memory for a few reasons not onto files
on local hard disc :/

Phil Crosland
 
Phil,

By your post, I'm not sure exactly sure what you are trying to accomplish
but I'll try an help with creating an System.Drawing.Icon object from a byte
array and then how to draw it to a System.Drawing.Graphics objects.

// Create a Bitmap from a Byte Array already in memory
Icon imgIcon = (Icon) Image.FromStream( new System.IO.MemoryStream(
abytByteArray ) );

// Draw this Icon to a System.Drawing.Graphics object
// in some kind of OnPaint Event from a WinForm Control
e.Graphics.DrawIcon( imgIcon, 0, 0 );

This method could be used to create any class derived from an Image.

Hope this helps.
 
Thank you! exactly what I was after. slightly altered as the referenced
interent resources coudl be any image type not icons but this is working:

WebClient wcTemp = new WebClient();
byte[] myDataBuffer =
wcTemp.DownloadData(this.txtGeneralFilePath.Text);
//create imTemp from the interent
Image imTemp = Image.FromStream(new
System.IO.MemoryStream(myDataBuffer));

Phil Crosland
 
Back
Top