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);
}用XML读的 10几张大图 怎么优化?
{
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);
}用XML读的 10几张大图 怎么优化?
private void GetImageByObject(out Bitmap image, object imgRow)
{
image = null; if (imgRow != null && !Convert.IsDBNull(imgRow))
{
byte[] bitBmp = (byte[])imgRow; using (System.IO.MemoryStream ms = new System.IO.MemoryStream(bitBmp))
{
image = new Bitmap(ms);
}
}
}
//将图片转成2进制数据
private void GetByteByImage(out byte[] bytPicture, Image image)
{
bytPicture = null; if (image != null)
{
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
Bitmap temp = new Bitmap(image); temp.Save(ms, image.RawFormat);
bytPicture = ms.ToArray();
}
}
}
还真不知道怎么办,在xml下文章把
user.Source = new BitmapImage可以把:
new BitmapImage显示创建一个索引:
img =new BitmapImage
要是不知道就只能等待垃圾回收了
没什么难得吧
这句代码并不知道你add后干嘛了。
你自己猜知道你user什么时候不用。
动态加载写在大图片带来的io负担比内存占用更低效。
你的代码并没有描述出你何时不用那个图片了。你如果这样,最好提供对图片的撞在卸载操作,并使用图片的地方都做判断避免null。
另外你可以user编写析构函数,释放图片。
如果你做缩略图使用,可以考虑创建固定尺寸的位图,读取的图片调用DrawImage绘制到你的位图上。显示的就是位图,位图你固定大小就不大了。这样绘制完就说明原本图不用,可以dispose了。
你代码没描述清晰你问题。
主要是看你在什么时候不用!