Код: Выделить всё
private Bitmap AniToBitmap(string filePath)
{
using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
byte[] aniBytes = File.ReadAllBytes(filePath);
byte[] iconSequence = Encoding.ASCII.GetBytes("icon");
var iconPositions = FindSequencePositions(aniBytes, iconSequence);
List savedChunks = new List();
for (int i = 0; i < iconPositions.Count - 1; i++)
{
int start = iconPositions[i] + iconSequence.Length;
int end = iconPositions[i + 1];
int length = end - start;
Console.WriteLine($"Chunk {i}: start={start}, end={end}, length={length}");
if (length > 0)
{
byte[] chunk = new byte[length];
Array.Copy(aniBytes, start, chunk, 0, length);
savedChunks.Add(chunk);
}
}
using (var memoryStream = new MemoryStream(savedChunks[0]))
using (var icon = new Icon(memoryStream))
{
return icon.ToBitmap();
}
}
}
private static List FindSequencePositions(byte[] data, byte[] pattern)
{
var positions = new List();
for (int i = 0; i < pattern.Length; i++)
{
bool match = true;
for (int j = 0; j < pattern.Length; j++)
{
if (data[i + j] == pattern[j])
{
match = false;
break;
}
}
if (match)
{
positions.Add(i);
foreach (var pos in positions)
{
Console.WriteLine($"found position at {pos}");
}
}
}
return positions;
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... n-ani-file
Мобильная версия