Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get the images scanned from the scanner and then convert the intpr to bitmap , after that I have added the images to the imagelist and displayed it in Listview using the following code :
case TwainCommand.TransferReady:
   {
   ArrayList pics = tw.TransferPictures();
   EndingScan();
   tw.CloseSrc();
   picnumber++;
   Bitmap myimg;
   for( int i = 0; i < pics.Count; i++ )
      {
      IntPtr img = (IntPtr) pics[ i ];
      myimg = DibToImage.WithHBitmap(GlobalLock(img));
      Image image = new Bitmap(myimg);
      imageList1.Images.Add(image);
      }
   for (int j = 0; j < this.imageList1.Images.Count; j++)
      {
      ListViewItem item = new ListViewItem();
      item.ImageIndex = j;
      this.listView1.Items.Add(item);
      }

and on images checked I displayed it in a picture box using theis code :
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
   {
   for (int k = 0; k < listView1.CheckedIndices.Count; k++)
      {
      // StrSelected = StrSelected + "[" + (k + 1) + "]  ";
      // Get the item ( as ListViewItem ) at the selected index.
      //ListViewItem lvi = listView1.Items[listView1.CheckedIndices[k]];
      // Get the subItem for the the selected item
      pictureBox1.Image = imageList1.Images[listView1.CheckedIndices[k]];
      pictureBox1.Visible = true;
      pictureBox1.Size = new Size(200, 256);
      }
   }

the problem is that I am not getting the reall image size which is scanned I am getting in the picture box only the smallimagelist items...

so :
1-how to display the real image size ?
2-I want to delete the items checked in the listview and imagelist...

I want your urgent help ..
regards...

[edit]Reformat the code and correct code block tags - OriginalGriff[/edit]
Posted
Updated 6-Nov-10 1:59am
v2
Comments
Smithers-Jones 6-Nov-10 8:02am    
"I want your urgent help .. " - Do not urge people. If somebody helps you, they do so for free, so don't urge!

1 solution

http://msdn.microsoft.com/en-us/library/system.windows.forms.imagelist.imagesize.aspx[^]
In the remark section it says: Setting the ImageSize property prior to adding images to the image collection causes the images to be resized to the image size specified. I would suggest you to store all the images in separate member of type List. Whenever you add an image to your ImageList, you add the same Image here also.
C#
List<Image> actualImageList;
public Form1()
{
    InitializeComponent();
    actualImageList = new List<Image>();
}

And so
C#
case TwainCommand.TransferReady:
   ...
   for (int j = 0; j < this.imageList1.Images.Count; j++)
      {
      ListViewItem item = new ListViewItem();
      item.ImageIndex = j;
      this.listView1.Items.Add(item);
      this.actualImageList.Add(item);
      }

Display the coressponding image from the actualImageList instead
Note: The code you've added to this function is kind of messy. You are iterating on a collection and changing the same properties of the same pictureBox1. In the result it will end up displaying the last checked image. Anyway, I didn't correct the code, as I have no information about your requirements.

C#
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
   {
   for (int k = 0; k < listView1.CheckedIndices.Count; k++)
      {
      // StrSelected = StrSelected + "[" + (k + 1) + "]  ";
      // Get the item ( as ListViewItem ) at the selected index.
      //ListViewItem lvi = listView1.Items[listView1.CheckedIndices[k]];
      // Get the subItem for the the selected item
      pictureBox1.Image = actualImageList[CheckedIndices[k]];
      pictureBox1.Visible = true;
      pictureBox1.Size = new Size(200, 256);
      }
   }


Remember that the ImageList class is designed to store images of the same size, and especially for ListView control it has to be mostly used for displaying the items.
For deleting I would suggest the following method.

C#
private void DeleteChecked()
{
	while (listView1.CheckedItems.Count > 0)
	{ 
		ListViewItem item = listView1.CheckedItems[0];
		imageList1.Images.RemoveAt(item.ImageIndex);
		actualImageList.RemoveAt(item.ImageIndex);
		listView1.Items.Remove(item);
	}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900