图片清单 [英] imagelist

查看:69
本文介绍了图片清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从扫描仪获取图像,然后将intpr转换为位图,之后,我将图像添加到图像列表并使用以下代码在Listview中显示:

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);
      }


并在检查的图像上使用theis代码将其显示在图片框中:


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);
      }
   }


问题是我没有得到要扫描的实际图像大小,而在图片框中仅得到了smallimagelist项目...

所以:
1-如何显示实际图像尺寸?
2-我要删除在列表视图和图像列表中选中的项目...

我需要您的紧急帮助..
问候...

重新格式化代码并更正代码块标签-OriginalGriff [/edit]


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]

推荐答案

^ ]
在备注部分中说:在将图像添加到图像集合之前设置ImageSize属性会导致将图像调整为指定的图像大小.我建议您将所有图像存储在List 类型的单独成员中.每当将图像添加到ImageList时,都在此处也添加相同的图像.
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.
List<Image> actualImageList;
public Form1()
{
    InitializeComponent();
    actualImageList = new List<Image>();
}


等等


And so

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);
      }


而是显示来自实际图像列表的核心图像
注意:您添加到此功能的代码有点混乱.您正在迭代一个集合并更改同一pictureBox1的相同属性.结果,它将最终显示最后检查的图像.无论如何,我没有更正代码,因为我没有关于您要求的信息.


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.

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);
      }
   }



请记住,ImageList类旨在存储相同大小的图像,尤其是对于ListView控件,它必须主要用于显示项目.
对于删除,我建议使用以下方法.



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.

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);
	}
}


这篇关于图片清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆