8,707
社区成员




using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage ( )
{
InitializeComponent ( );
}
private void btnAmplify_Click ( object sender, RoutedEventArgs e )
{
msg.Text = "test!";
}
private void btnSearch_Click ( object sender, RoutedEventArgs e )
{
System.Uri uri = new Uri(@"http://www.google.com.hk/images/nav_logo8.png");
WebClient imgLoader = new WebClient ( );
imgLoader.DownloadStringCompleted += new OpenReadCompletedEventHandler ( imgLoader.DownloadStringCompleted );
imgLoader.DownloadStringAsync ( new Uri ( uri ) );
System.Net.WebRequest mwr = System.Net.WebRequest.Create( uri );
System.Net.WebResponse mrsp = mwr.BeginGetResponse( );
string mapFileName = @"C:\Documents and Settings\Administrator\桌面\wmsmap.gif";
//System.IO.Path.GetTempPath() + @"wmsmap.gif";
System.IO.File.OpenWrite( mrsp.GetResponseStream ( ), mapFileName)
//copyStreamToFile ( mrsp.GetResponseStream ( ), mapFileName );
Image myImage = new Image();
myImage.Source = new BitmapImage(new Uri("myPicture.jpg", UriKind.RelativeOrAbsolute));
LayoutRoot.Children.Add(myImage);
image1. (mapFileName);
}
private static void copyStreamToFile(System.IO.Stream stream, string destination)
{
System.IO.BinaryReader bs = new ;
{
using (System.IO.FileStream os = System.IO.File.OpenWrite(destination))
{
byte[] buffer = new byte[2 * 4096];
int nBytes;
while ((nBytes = bs.Read(buffer, 0, buffer.Length)) > 0)
{
os.Write(buffer, 0, nBytes);
}
}
}
}
}
}