Reputation: 3405
I wanted to show my pics in picturebox. but also wanted to show a preview of pics. When user select a pic, it is shown in picbox but i have problem in resoulution.
Here is my code
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
ofd = new OpenFileDialog();
ofd.Title = "Open an Image File";
ofd.FileName = "";
ofd.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (ofd.ShowDialog() == DialogResult.OK)
{
DirectoryInfo dir = new DirectoryInfo(@"c:\pic");
foreach (FileInfo file in dir.GetFiles())
{
this.imageList1.Images.Add(Image.FromFile(file.FullName));
}
this.listView1.View = View.LargeIcon;
this.imageList1.ImageSize = new Size(40, 40);
this.listView1.LargeImageList = this.imageList1;
for (int j=0; j < this.imageList1.Images.Count; j++) {
ListViewItem item = new ListViewItem();
item.ImageIndex = j;
listView1.Items.Add(item);
ListViewItem item2 = new ListViewItem();
item2.SubItems.Add(j.ToString());
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
int i = this.listView1.FocusedItem.Index;
this.PicBox1.Image = this.imageList1.Images[i];
}
On click i see only image of resolution of (40,40) becuse i have set it this.imageList1.ImageSize = new Size(40, 40); and not orignal size. How can I have it. 2- I want to write also image names and index(image no) under each images. Its it possible. reagrsd,
Upvotes: 1
Views: 5928
Reputation: 81
-Create a new imagelist (imagelist1)**
-Add images to your imagelist
-Create a new listview (listview1)
-Create a picturebox (picturebox1)
-Create a new button (button1)
-Create another button (button2)**
-Import images from imagelist1 to listview1
private void button1_Click(object sender, EventArgs e)
{
listView1.Scrollable = true;
listView1.View = View.LargeIcon;
imageList1.ImageSize = new Size(100, 100);
listView1.LargeImageList = imagelist1;
for (int i = 0; i < imagelist1.Images.Count; ++i)
{
string s = imagelist1.Images.Keys[i].ToString();
ListViewItem lstItem = new ListViewItem();
lstItem.ImageIndex = i;
lstItem.Text = s;
listView1.Items.Add(lstItem);
}
}
- Set the selected image into your picture box from listview
private void button2_Click(object sender, EventArgs e)
{
if (this != null && listView1.SelectedItems.Count > 0)
{
ListViewItem lvi = listView1.SelectedItems[0];
string imagekeyname = lvi.Text;
if (this.pictureBox1.Image != null)
{
this.pictureBox1.Image.Dispose();
this.pictureBox1.Image = null;
}
//set the selected image into your picturebox
this.pictureBox1.Image = imagelist1.Images[imagekeyname];
}
}
and its done.
Upvotes: 0
Reputation: 1965
You should save the original picture in another container like List<>
and display the original image from the list and not from the imagelist :)
Upvotes: 1
Reputation: 2330
I suppose, that after you have loaded an image to the imageList with resolution 40, 40, there is no way to make it higher.
Upvotes: 2