【发布时间】:2014-06-18 10:33:34
【问题描述】:
我尝试使用此代码使用网站截图 DLL 获取网站的缩略图 但图像没有显示在我的项目控件中,我没有收到任何错误。
public void ImagesActivities()
{
//sep s = new sep();
var images = new ObservableCollection<sep>();
var wcf = new ServiceReferenceSites.SiteEnPlusServiceClient();
foreach (var item in wcf.GetAll())
{
sep s = new sep();
s.title = item.title;
s.thumbnail = (System.Drawing.Image)GetThumbImage(item.urlsite);
images.Add(s);
}
_activityList.ItemsSource = images;
}
private Bitmap GetThumbImage(string s)
{
WebsitesScreenshot.WebsitesScreenshot _Obj;
_Obj = new WebsitesScreenshot.WebsitesScreenshot();
WebsitesScreenshot.WebsitesScreenshot.Result _Result;
_Result = _Obj.CaptureWebpage(s);
if (_Result == WebsitesScreenshot.
WebsitesScreenshot.Result.Captured)
{
_Obj.ImageWidth = 200;
_Obj.ImageHeight = 100;
_Obj.ImageFormat = WebsitesScreenshot.
WebsitesScreenshot.ImageFormats.PNG;
return _Obj.GetImage();
}
else
return null;
}
这是我的 itemscontrol 的代码:
<ItemsControl x:Name="_activityList" HorizontalAlignment="Right" Margin="0,10,10,10" Width="760">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="5" IsItemsHost="True"/>
<!--<StackPanel Orientation="Horizontal" IsItemsHost="True"/>-->
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Grid.Row="0" Margin="10,20,0,0" BorderThickness="0" Height="100" Width="200">
<Button.Background>
<ImageBrush ImageSource="{Binding thumbnail}" />
</Button.Background>
</Button>
<TextBlock Grid.Row="1" x:Name="nom" Margin="10,0,0,0" TextAlignment="Center" Text="{Binding title}" VerticalAlignment="Center"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
这是我的 sep 课程
public class sep
{
public string title { get; set; }
public System.Drawing.Image thumbnail { get; set; }
}
谁能帮帮我。
【问题讨论】:
-
你的“sep”类的定义是什么?
-
我编辑我的问题,你可以定义我的 sep 类
-
答案已修改.....
标签: c# wpf thumbnails itemscontrol