Initial commit: application ColorPicker (palette, pipette ecran, couleur de dossier)
This commit is contained in:
34
tests/IconPreview.cs
Normal file
34
tests/IconPreview.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
namespace ColorPickerApp
|
||||
{
|
||||
internal static class IconPreview
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
string dir = Path.Combine(Path.GetTempPath(), "cp_preview");
|
||||
Directory.CreateDirectory(dir);
|
||||
FolderColorizer.ApplyColor(dir, Color.FromArgb(220, 40, 60));
|
||||
|
||||
byte[] icoBytes = File.ReadAllBytes(Path.Combine(dir, ".colorpicker_folder.ico"));
|
||||
int count = System.BitConverter.ToUInt16(icoBytes, 4);
|
||||
// trouver l'entree 256x256 (largeur stockee = 0) avec le plus grand bytesInRes
|
||||
int bestOffset = -1, bestSize = -1, bestLen = 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int entryOffset = 6 + i * 16;
|
||||
int w = icoBytes[entryOffset];
|
||||
int len = System.BitConverter.ToInt32(icoBytes, entryOffset + 8);
|
||||
int off = System.BitConverter.ToInt32(icoBytes, entryOffset + 12);
|
||||
if (w == 0 && len > bestLen) { bestLen = len; bestOffset = off; bestSize = w; }
|
||||
}
|
||||
var pngBytes = new byte[bestLen];
|
||||
System.Array.Copy(icoBytes, bestOffset, pngBytes, 0, bestLen);
|
||||
File.WriteAllBytes(Path.Combine(Path.GetTempPath(), "cp_icon_preview.png"), pngBytes);
|
||||
|
||||
FolderColorizer.RestoreDefault(dir);
|
||||
Directory.Delete(dir, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user