私は、 8つの異なる画像を1つずつ表示する8つPictureBox
のesを動的に作成するフォームを持っています。画像は50KbのJPEGです。問題は、ユーザーが 300 枚の写真 (38 枚のパネルのようなもの) を表示できるようにしたいことですが、画像をes にロードするたびに、プログラムは 5 ~ 7Mb の RAM メモリをさらに使用します(Windows のタスク マネージャーから確認できます)。その増分を減らすにはどうすればよいですか? 私の写真はそれほど大きくありません。プレビューを表示したいだけで、品質は気にしません。これが私がesを作成する方法です:Panel
PictureBox
PictureBox
PictureBox
private void buttonAdd_Click(object sender, EventArgs e)
{
Panel pan = new Panel();
PictureBox pic1 = new PictureBox();
pic1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
pic1.Location = new System.Drawing.Point(208, 5);
pic1.Name = "panel" + ctr.Count().ToString() + "pictureBox1";
pic1.Size = new System.Drawing.Size(100, 100);
pic1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
///
/// Same thing other 7 times with differents name and location
///
pan.Location = new System.Drawing.Point(12, 55);
pan.Name = "panel" + ctr.Count().ToString();
pan.Size = new System.Drawing.Size(1088, 129);
pan.TabIndex = 0;
pan.AllowDrop = true;
pan.BackColor = System.Drawing.SystemColors.ControlLight;
pan.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
pan.Controls.Add(pic1);
///
/// Same thing other 7 times
///
this.Controls.Add(pan);
}
そして、ここに私がそれらを埋める方法があります:
void buttonClickEvent(object sender, EventArgs e)
{
string[] files= Directory.GetFiles("mylocalpath");
foreach(string x in files)
{
string imgIndex= x.Remove(0,x.LastIndexOf("_")+1).Remove(1);
PictureBox pic=pictureBox1;
//I get it everytime from imgIndex and sender's parent,
//too much code to show now
pic.ImageLocation = x;
}
}