我正在开发一个编辑图标的项目,我需要加载一个图标。我使用以下代码保存此图标:
var sd = new SaveFileDialog();
sd.ShowDialog();
sd.Filter = "File *.ico|*.ico";
sd.FilterIndex = 0;
var path = sd.FileName;
if (!sd.CheckPathExists) return;
var w = new WriteableBitmap(Dimention, Dimention, 1, 1, PixelFormats.Pbgra32, null);
var pix = new int[Dimention,Dimention];
for (int i = 0; i < Dimention; i++)
for (int j = 0; j < Dimention; j++)
pix[i, j] = ToArgb(IconCanvas.Board[i, j].Background.Color);
w.WritePixels(new Int32Rect(0, 0, Dimention, Dimention), pix, Dimention*4, 0, 0);
var e = new BmpBitmapEncoder();
e.Frames.Add(BitmapFrame.Create(w));
var file = new FileStream(path, FileMode.Create);
e.Save(file);
file.Close();
所以,我需要从这些保存的图像中获取一个 Color[,] 。我假设图标的大小是正方形 (width = height) 。谢谢你的帮助。