WinForms:具有不同图像尺寸的ListView的ImageList
我有一个 ListView
,其 View
属性设置为 LargeIcon
。我有一个 ImageList
作为 ListView
的图像源。
我想要的是在 ListView
中显示垂直和水平方向的图像,但 ImageList
对于其集合中的所有图像只有一个属性 ImageSize
,所以例如,如果我将该属性设置为 150x100 并向集合添加垂直图像 (100x150) - ListView
会自动将其拉伸到 150x100。
因此,据我了解,我需要一些 ImageList
,其中每个图像都以其原始大小存储。关于如何做到这一点有什么想法吗? 提前致谢。
I have a ListView
with View
property set to LargeIcon
. And I have an ImageList
as image source for ListView
.
What I want is to display both vertically and horizontally oriented images in ListView
but ImageList
have only a single property ImageSize
for all images in its collection so for example if I set that property to 150x100 and add a vertical image (100x150) to collection - ListView
automatically stretches it to 150x100.
So as I understand I need some ImageList
, in which every image is stored with its original size. Any thoughts about how to do that?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己也遇到过这个问题,这就是我所做的,我希望它也能帮助你,首先确定你将使用的最大图像尺寸(例如200x200),然后使用具有透明背景的Png或Gif图像(均为200x200)。
看看我作为示例创建的这两个图像。
但我这样做是为了避免拉伸:
I have had this problem myself, Here is what I did, I hope it will help you as well, first determine the biggest image size you would use ( for example 200x200) then use Png or Gif images (all 200x200) with transparent backgrounds.
have a look at these two images i have created as an example.
but I make it like this to avoid stretching:
为了避免拉伸,您可以使用交叉乘法。
或者
在代码中,它看起来像这样
或者
和
或者
然后,在创建新位图时,您可以使用所需的大小和派生的大小在新位图上绘制缩放图像。
To keep from stretching you can use cross-multiplication.
or
In code it looks something like this
or
and
or
Then when creating your new bitmap you can draw a scaled image on the new bitmap using the desired size and the derived size.