WP7备注(8)(WebClient读取图片)

远程图片数据申请:

XNA:

protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
WebClient webClient = new WebClient();
webClient.OpenReadCompleted += OnWebClientOpenReadCompleted;
webClient.OpenReadAsync(new
Uri("http://www.charlespetzold.com/Media/HelloWP7.jpg"));
}
void OnWebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs args)
{
if (!args.Cancelled && args.Error == null)
{
helloTexture = Texture2D.FromStream(this.GraphicsDevice, args.Result);
}
}

Silverlight:

protected override void OnManipulationStarted(ManipulationStartedEventArgs args)
{
WebClient webClient = new WebClient();
webClient.OpenReadCompleted += OnWebClientOpenReadCompleted;
webClient.OpenReadAsync(new
Uri("http://www.charlespetzold.com/Media/HelloWP7.jpg"));
args.Complete();
args.Handled = true;
base.OnManipulationStarted(args);
}
void OnWebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs args)
{
if (!args.Cancelled && args.Error == null)
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(args.Result);
img.Source = bmp;
}
}

图片编译进入DLL字符串格式:

"/SilverlightDemo;component/Images/HelloWorld.png"

原文地址:https://www.cnblogs.com/otomii/p/2029528.html