动态显示数百张照片 [英] Display hundreds images dynamically

查看:132
本文介绍了动态显示数百张照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建能够显示一个电影院大厅(不知道确切的词)架构的一种形式。基本上我要显示大量可改变点击颜色(状态)独立座椅般的画面(由其它来源提供)。

I have to create a form capable of displaying a cinema-hall (don't know the exact word) schema. Essentially I have to display a large number (given by another source) of independent chair-like images which can change color (status) on click.

我在网上冲浪搜索一个解决方案,但我真的没有线索如何进行管理。
有人能帮助我吗?

I surf the web searching for a solution but I really don't have a clue how to manage this. Can someone help me?

推荐答案

如果您需要绘制很多的图像最好的办法是用面板控制和处理通过任何处理OnPaint事件,甚至更好绘制自己:创建一个从Panel控件继承和重写Paint方法自定义控件。对于如何在.NET中创建自定义绘制的控件实例在线看。

If you need to draw that many images your best bet is to use a panel control and handle the drawing yourself by either handling the OnPaint event or even better: creating a custom control that inherits from the Panel control and which overrides the Paint method. Look online for examples of how to create custom-painted controls in .NET.

不要试图创建数百个使用图像控件或其他这样的控制,因为它增加了图像开销很大。

Do not try to create hundreds of images using Image controls or other such controls because it adds to much overhead.

在Paint方法,您可以使用的的DrawImage 函数来绘制根据不同状态下的椅子(即选择或不选择)。你可以通过它循环存储椅子的状态在内存一维或二维数组,然后在paint方法绘制每个椅子上,计算基于其指数屏幕上的椅子的位置:

In the Paint method, you can use the DrawImage function to draw the chairs based on the different states (i.e. selected or not-selected). You can store the states of the chairs in a one- or two-dimensional array in memory and then loop through it in the Paint method to draw each chair, computing the position of the chair on-screen based on its' index:

for(int chairIndex = 0; chairIndex < chairsCount; chairIndex++)
{
  // compute the on-screen position of each chair
  chairX = (chairIndex % chairsPerLine) * chairWidh;
  chairY = (chairIndex / chairsPerLine) * chairHeight;

  // and read the current state from the array
  chairState = chairsArray[chairIndex];

  // then draw the chair image in the graphics context
  switch(chairState)
  {
     case /* SELECTED */
       .. DrawImage(selectedImage, new Point(chairX, chairY));
     case /* NOT-SELECTED */
       .. DrawImage(nonSelectedImage, new Point(chairX, chairY));
  }
}

您还必须处理鼠标事件打-test当用户点击一个椅子切换它在内存中的状态。

You will also have to handle mouse events to "hit-test" when a user clicks a chair to toggle it's state in memory.

// compute chairIndex based on mouse position (for hit-test)
chairIndex = mouseX / chairWidth + (mouseY / chairHeight) * chairsPerLine;
// then toggle state accordingly

上面的代码片段假定您以前定义一些变量,已加载不同的椅子图像转换成两个或多个变量,而您使用的是一维数组存储椅子状态。

这篇关于动态显示数百张照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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