如何将一个图片的网络地址 保存为本地图片

寂寞豆腐 2012-07-12 10:48:36
rt
还有就是如何将提供一个服务器文件路径,把文件下载到本地,并删除服务器文件
...全文
394 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jv9 2012-07-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]
引用 3 楼 的回复:
可以利用WebClient下载网络图片,例如:


XML code

<UserControl x:Class="SilverlightApplication1.WebClientDownload"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http……
[/Quote]

private void btnDownload_Click(object sender, RoutedEventArgs e)
{
//檔案放在ClientBin的上層
wc.OpenReadAsync(new Uri("../YY.jpg", UriKind.Relative));
}
寂寞豆腐 2012-07-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
可以利用WebClient下载网络图片,例如:


XML code

<UserControl x:Class="SilverlightApplication1.WebClientDownload"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://s……
[/Quote]

我是想要把它保存到本地的盘符。如保存为jpg格式。这样的。不是显示在页面上。
寂寞豆腐 2012-07-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
可以利用WebClient下载网络图片,例如:


XML code

<UserControl x:Class="SilverlightApplication1.WebClientDownload"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://s……
[/Quote]


终于等到你了。。
jv9 2012-07-13
  • 打赏
  • 举报
回复
可以利用WebClient下载网络图片,例如:


<UserControl x:Class="SilverlightApplication1.WebClientDownload"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc=
"http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="0.09*"/>
<RowDefinition Height="0.17*"/>
<RowDefinition Height="0.74*"/>
</Grid.RowDefinitions>
<Canvas Canvas.Top="70" Grid.RowSpan="3">
<Rectangle x:Name="progressRectangle" Canvas.Left="96" Height="10" Width="0" Fill="Maroon" Canvas.Top="42" />
<Rectangle Canvas.Top ="42" Canvas.Left="96" Height="10" Width="200" StrokeThickness="1" Stroke="Black" />
<TextBlock x:Name="progressText" Canvas.Top="36.545" Canvas.Left="302" Text="0%" FontSize="12" />
</Canvas>
<Button HorizontalAlignment="Left" Margin="23,8,0,16" Width="67" Grid.Row="1" Content="Download"
x:Name="btnDownload" Click="btnDownload_Click"/>
<Image Margin="8.5,8.5,8,8" Grid.Row="2" x:Name="img"/>
</Grid>
</UserControl>



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;
using System.Windows.Media.Imaging;
using System.Windows.Resources;

namespace SilverlightApplication1
{
public partial class WebClientDownload : UserControl
{
WebClient wc = null;

public WebClientDownload()
{
InitializeComponent();

wc = new WebClient();

wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
}

//進度
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressText.Text = e.ProgressPercentage.ToString();
progressRectangle.Width = (double)e.ProgressPercentage*2;
}

//下載完成,載入圖片
void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error != null) { return; }
BitmapImage bi = new BitmapImage();
bi.SetSource(e.Result);
img.Source = bi;

}

private void btnDownload_Click(object sender, RoutedEventArgs e)
{
//檔案放在ClientBin的上層
wc.OpenReadAsync(new Uri("../YY.jpg", UriKind.Relative));
}
}
}



结果如下:



详细请看:http://silverlightchina.net/html/tips/2011/0308/5912.html
Architecture Net 2012-07-12
  • 打赏
  • 举报
回复
使用WebClient就可以下载制定Url地址的图片
寂寞豆腐 2012-07-12
  • 打赏
  • 举报
回复
anyone can give me a help

8,757

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧