在VB年代有专门的IMAGE数组控件,在.NET下却没有了这个控件,只能自己来实现。今天看DEVEXPRESS代码摘出来学习了一下![](https://www.cnblogs.com/Emoticons/tusiji/203330198.gif)
public class ImageCollectionEditor
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
private Image GetImageFromCollection(Image iml, int width, int height, int wIndex, int hIndex)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Bitmap res = new Bitmap(width, height);
res.SetResolution(iml.HorizontalResolution, iml.VerticalResolution);
Graphics g = Graphics.FromImage(res);
g.DrawImage(iml, 0, 0, new Rectangle(width * wIndex, height * hIndex, width, height), GraphicsUnit.Pixel);
g.Dispose();
return res;
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 获取IMAGE数组
/// </summary>
/// <param name="sourceImage">源图片</param>
/// <param name="vertical">图片方向</param>
/// <param name="InnerList">IMAGELIST控件</param>
public virtual void AddImageStrip(Image sourceImage, bool vertical,ref System.Windows.Forms.ImageList InnerList)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Size size = new Size (18,18);
int index = 0;
for (int i = vertical ? sourceImage.Height : sourceImage.Width; i > 0; i -= vertical ? size.Height : size.Width)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
InnerList.Images.Add(GetImageFromCollection(sourceImage, size.Width, size.Height, vertical ? 0 : index, vertical ? index : 0));
index++;
}
}
MSDN针对DrawImage 的解释
Graphics..::.DrawImage 方法 (Image, array<Point>[]()[])
在指定位置并且按指定形状和大小绘制指定的 Image。
命名空间: System.Drawing
程序集: System.Drawing(在 System.Drawing.dll 中)
public void DrawImage(
Image image,
Point[] destPoints
)
- image
- 类型:System.Drawing..::.Image
要绘制的 Image。
- destPoints
- 类型:array<System.Drawing..::.Point>[]()[]
由三个 Point 结构组成的数组,这三个结构定义一个平行四边形。
DEMO下载