Create ImageCollectionExtension

-Added basic Insert method for ImageCollections
This commit is contained in:
MayNL
2026-04-14 19:09:56 -04:00
parent 8a45557f55
commit dcb7624ccc
4 changed files with 41 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
using System.Windows.Forms;
using System.Windows.Forms;
namespace PckStudio.Controls
{

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PckStudio.Core.Extensions
{
public static class ImageCollectionExtensions
{
public static void Insert(this ImageList.ImageCollection _, int index, string key, Image image)
{
var images = new List<Image>();
var keys = new List<string>();
for (int i = 0; i < _.Count; i++)
{
keys.Add(_.Keys[i]);
images.Add(_[i]);
}
images.Insert(index, image);
keys.Insert(index, key);
_.Clear();
for (int i = 0; i < images.Count; i++)
{
_.Add(keys[i], images[i]);
}
}
}
}

View File

@@ -214,7 +214,7 @@ namespace PckStudio.Core.Extensions
Marshal.Copy(baseImageData.Scan0, baseImageBuffer, 0, baseImageBuffer.Length);
BitmapData overlayImageData = overlayImage.LockBits(new Rectangle(Point.Empty, overlayImage.Size),
BitmapData overlayImageData = overlayImage.LockBits(new Rectangle(Point.Empty, overlayImage.Size),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
byte[] overlayImageBuffer = new byte[overlayImageData.Stride * overlayImageData.Height];
@@ -258,7 +258,7 @@ namespace PckStudio.Core.Extensions
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
byte[] overlayImageBuffer = new byte[overlayImageData.Stride * overlayImageData.Height];
Marshal.Copy(overlayImageData.Scan0, overlayImageBuffer, 0, overlayImageBuffer.Length);
overlayImage.UnlockBits(overlayImageData);
@@ -282,4 +282,4 @@ namespace PckStudio.Core.Extensions
return bitmapResult;
}
}
}
}

View File

@@ -73,6 +73,7 @@
<Compile Include="Extensions\GraphicsExtensions.cs" />
<Compile Include="Extensions\ImageExtensions.cs" />
<Compile Include="Extensions\ImageLayoutDirection.cs" />
<Compile Include="Extensions\ImageCollectionExtensions.cs" />
<Compile Include="Extensions\ImageSection.cs" />
<Compile Include="Extensions\ListExtensions.cs" />
<Compile Include="Extensions\LocFileExtensions.cs" />