如果要从文件加载图像,可以使用FromFile 方法。来自 msdn 的例子:private void Button2_Click(System.Object sender, System.EventArgs e){ try { Bitmap image1 = (Bitmap) Image.FromFile(@"C:\Documents and Settings\" + @"All Users\Documents\My Music\music.bmp", true); TextureBrush texture = new TextureBrush(image1); texture.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; Graphics formGraphics = this.CreateGraphics(); formGraphics.FillEllipse(texture, new RectangleF(90.0F, 110.0F, 100, 100)); formGraphics.Dispose(); } catch(System.IO.FileNotFoundException) { MessageBox.Show("There was an error opening the bitmap." + "Please check the path."); }}如果要从流加载图像,也可以使用FromStream 方法。
2 回答
![?](http://img1.sycdn.imooc.com/545863e80001889e02200220-100-100.jpg)
达令说
TA贡献1821条经验 获得超6个赞
您已经在代码中使用了一些 Linq,所以只需多使用一点。Linq 中的Take()方法将完全符合您的要求:
@foreach (var orderline in order.OrderLines.DistinctBy(ol => ol.imageURL).Take(5))
{
<img height="40" src="@orderline.imageURL" alt="@(orderline.Listing.Title.Length > 15 ? orderline.Listing.Title.Substring(0, 15) : orderline.Listing.Title)" />
}
将Take(5)在年底加入我意味着你只能通过迭代最大的5个项目
![?](http://img1.sycdn.imooc.com/54584cde0001d19202200220-100-100.jpg)
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
将您的 foreach 更改为 for 循环
@for(var i = 0; i < 5; i++)
Your code goes here using thing[i]
- 2 回答
- 0 关注
- 214 浏览
添加回答
举报
0/150
提交
取消