简体   繁体   English

具有ImageList的图像的面向对象设计

[英]Object Oriented Design for an Image with ImageList

I am making a class which represents and Image, and with Windows, you store images in ImageList controls. 我正在制作一个表示和图像的类,在Windows中,您将图像存储在ImageList控件中。 This class will be used to handily add images to other controls like ListViews or Buttons, or simply to draw on the screen. 该类将用于方便地将图像添加到其他控件(如ListViews或Buttons),或仅在屏幕上绘制。 My question is: what is the proper design for something like this? 我的问题是:这样的东西正确的设计是什么? Should each Image have it's own ImageList of one image, or should the Image class have one giant ImageList for all the instances of it, or what? 每个图像应该具有一个图像的自己的ImageList,还是Image类应针对其所有实例具有一个巨型ImageList,或者什么? I don't know much about the internals of the Windows classes so I don't know how "heavy" the ImageList class is, but if it's relatively inexpensive, I was leaning toward the "each instance has it's own imagelist." 我对Windows类的内部内容了解不多,所以我不知道ImageList类的“繁重”程度,但是如果它相对便宜,我就会倾向于“每个实例都有它自己的图像列表”。 What do you recommend? 您有什么推荐的吗?

Generally, I would recommend something in between. 通常,我会建议介于两者之间。

It seems silly to have a different image list for each image. 每个图像都有不同的图像列表似乎很愚蠢。 They're designed to store collections of images and make managing these collections more efficient, not so much to hold a single image. 它们旨在存储图像集合,并使管理这些集合更加有效,而不是仅保存一个图像。

Then again, there are drawbacks to trying to use one giant image list for all of your images. 再有,尝试对所有图像使用一个巨型图像列表也有弊端。 Namely, all of the images in an image list must be of the same size. 即,图像列表中的所有图像必须具有相同的尺寸。 If this isn't true of your images, you'll need to place them in separate image lists. 如果您的图片并非如此,则需要将它们放在单独的图片列表中。

But more to the point, I'm not really sure why you're considering creating an image class that contains an image list in the first place. 但更重要的是,我不太确定为什么要考虑创建一个首先包含图像列表的图像类。 Unless you're going to be storing icons/cursors or need to worry about masks, why not just encapsulate a handle to the bitmap representing the image? 除非您要存储图标/光标或需要担心遮罩,否则为什么不只封装表示图像的位图的句柄? That's the same thing you're going to be passing into the image list's "Add" method anyway. 无论如何,这都是您要传递到图像列表的“添加”方法中的同一件事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM