我尝试使用包含另一个包含图像的类列表的类,通过图像列表填充列表视图。
专辑类:
public class Camera
{
List<Photo> _photos = new List<Photo>();
string _title = string.Empty;
public List<Photo> Photos
{
get
{
return this._photos;
}
set
{
this._photos = value;
}
}
照片类
public class Photo
{
Image _photo = null;
String _description = string.Empty;
public Image PhotoImage
{
get
{
return this._photo;
}
set
{
this._photo = value;
}
}
相关代码
public Form1()
{
InitializeComponent();
btnCapture.Enabled = false;
this.listAlbum.View = View.LargeIcon;
this.imageList1.ImageSize = new Size(64, 48);
this.listAlbum.LargeImageList = this.imageList1;
foreach (EncoderDevice edv in EncoderDevices.FindDevices(EncoderDeviceType.Video))
{
comboCameraSelect.Items.Add(edv.Name);
}
}
private Image GetScreenShot()
{
Image temp = null;
using (Image screenImage = new Bitmap(panelPreview.Width, panelPreview.Height))
{
using (Graphics g = Graphics.FromImage(screenImage))
{
Rectangle rectanglePanelVideoPreview = panelPreview.Bounds;
Point sourcePoints = panelPreview.PointToScreen(new Point(panelPreview.ClientRectangle.X, panelPreview.ClientRectangle.Y));
g.CopyFromScreen(sourcePoints, Point.Empty, rectanglePanelVideoPreview.Size);
}
temp = screenImage;
}
return temp;
}
public void btnCapture_Click(object sender, EventArgs e)
{
Photo p = new Photo();
p.PhotoImage = GetScreenShot();
album.Photos.Add(p);
this.imageList1.Images.Add(p.PhotoImage);
ListViewItem item = new ListViewItem();
item.ImageIndex = j;
item.ImageKey = j.ToString();
this.listAlbum.Items.Add(item);
j = (j + 1);
}
当程序到达
时this.imageList1.Images.Add(p.PhotoImage);
它抛出一个异常,说参数无效,尽管它是一个图像。
列表视图似乎可以获得索引,因为滚动条在多个循环后出现,但没有显示任何拇指,也没有任何可选项。
非常感谢任何建议。
感谢。