Image _img = Image.FromFile("...");//大文件 Bitmap img = new Bitmap(200, 200);//实际显示 Graphics g = Graphics.FromImage(img); g.DrawImage(_img, new Rectangle(0, 0, img.Width, img.Height)); g.Dispose(); _img.Dispose(); this.pictureBox1.Image = img;
我用的是XML 循环读的 public void winLoad() { readXML xml = new readXML(); DataTable table = xml.ReadMiniDTXml(); for (int i = 0; i < table.Rows.Count; i++) { Image user = new Image(); user.Name = "u" + (i + 1).ToString();
user.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + table.Rows[i]["path1"].ToString().Trim())); user.Width = 100; user.Height = 100; this.stackPanel_Image.Children.Add(user); }然后用线程加载的 Thread thread = new Thread(DO); // thread.IsBackground = true; thread.Start(); public void AddImage() { winLoad();
} public void DO() { System.Windows.Application.Current.Dispatcher.BeginInvoke(new AddButtonDelegate(AddImage), DispatcherPriority.ContextIdle); }
Bitmap img = new Bitmap(200, 200);//实际显示
Graphics g = Graphics.FromImage(img);
g.DrawImage(_img, new Rectangle(0, 0, img.Width, img.Height));
g.Dispose();
_img.Dispose();
this.pictureBox1.Image = img;
public void winLoad()
{
readXML xml = new readXML();
DataTable table = xml.ReadMiniDTXml();
for (int i = 0; i < table.Rows.Count; i++)
{
Image user = new Image();
user.Name = "u" + (i + 1).ToString();
user.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + table.Rows[i]["path1"].ToString().Trim())); user.Width = 100;
user.Height = 100;
this.stackPanel_Image.Children.Add(user);
}然后用线程加载的
Thread thread = new Thread(DO);
// thread.IsBackground = true;
thread.Start();
public void AddImage()
{
winLoad();
}
public void DO()
{ System.Windows.Application.Current.Dispatcher.BeginInvoke(new AddButtonDelegate(AddImage), DispatcherPriority.ContextIdle); }