您的位置:首页 > 其它

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

2011-04-26 17:03 190 查看
 

远程图片数据申请:

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"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: