Created
September 7, 2013 10:40
-
-
Save sholfen/6474549 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Windows.Forms; | |
using System.Net; | |
using System.IO; | |
namespace TestGVWinAP | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
Image img = new Bitmap(@".\pic.jpg"); | |
List<DataContainer> list = new List<DataContainer>(); | |
list.Add(new DataContainer { Field1 = "1", Field2 = img, Field3 = "3" }); | |
list.Add(new DataContainer { Field1 = "A", Field2 = img, Field3 = "C" }); | |
list.Add(new DataContainer { Field1 = "D", Field2 = img, Field3 = "F" }); | |
var list2 = from s in list | |
select new { s.Field1, s.Field2 }; | |
this.dataGridView1.DataSource = list; | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
List<DataContainer> list = this.dataGridView1.DataSource as List<DataContainer>; | |
WebClient client = new WebClient(); | |
foreach (DataContainer item in list) | |
{ | |
byte[] bytes = client.DownloadData(@"http://cdn-pixiv.maid.tw/thumb/17997136_45953_thumb.jpg"); | |
Image img = new Bitmap(this.CreateImage(bytes)); | |
item.Field4=img; | |
item.Field1 = "aaa3"; | |
} | |
this.dataGridView1.Refresh(); | |
} | |
private Image CreateImage(byte[] bytes) | |
{ | |
MemoryStream oMemoryStream = new MemoryStream(bytes); | |
Image oImage = null; | |
Bitmap oBitmap = null; | |
oMemoryStream.Position = 0; | |
oImage = Image.FromStream(oMemoryStream); | |
oBitmap = new Bitmap(oImage); | |
return oBitmap; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment