Загрузка данных
using ImageMagick;
using FFMpegCore;
using System.IO;
namespace UltraConvert
{
public partial class Form1 : Form
{
// Твои списки расширений
private List<string> imageExt = new List<string> { ".jpg", ".jpeg", ".png", ".bmp", ".webp", ".heic", ".avif", ".tiff" };
private List<string> mediaExt = new List<string> { ".mp4", ".avi", ".mkv", ".mov", ".flv", ".mp3", ".wav", ".ogg", ".aac", ".m4a" };
public Form1()
{
InitializeComponent();
SetupTools();
}
private void SetupTools()
{
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
MagickNET.SetGhostscriptDirectory(baseDir);
GlobalFFOptions.Configure(options => options.BinaryFolder = baseDir);
}
private void btnSelectFiles_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog { Multiselect = true })
{
if (ofd.ShowDialog() == DialogResult.OK)
{
foreach (string file in ofd.FileNames)
{
if (!listBoxQueue.Items.Contains(file))
listBoxQueue.Items.Add(file);
}
}
}
}
private void btnClear_Click(object sender, EventArgs e)
{
listBoxQueue.Items.Clear();
lblStatus.Text = "Очередь пуста";
}
private async void btnConvert_Click(object sender, EventArgs e)
{
if (listBoxQueue.Items.Count == 0 || comboBoxFormats.SelectedItem == null) return;
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string selectedTarget = comboBoxFormats.SelectedItem.ToString()!;
btnConvert.Enabled = false;
for (int i = 0; i < listBoxQueue.Items.Count; i++)
{
string filePath = listBoxQueue.Items[i].ToString()!;
lblStatus.Text = $"Обработка: {Path.GetFileName(filePath)}";
try
{
await Task.Run(() => ProcessLogic(filePath, desktopPath, selectedTarget));
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка в {Path.GetFileName(filePath)}: {ex.Message}");
}
}
lblStatus.Text = "Готово! Всё на рабочем столе.";
btnConvert.Enabled = true;
}
private void ProcessLogic(string input, string outputDir, string targetFormat)
{
string ext = Path.GetExtension(input).ToLower();
string name = Path.GetFileNameWithoutExtension(input);
string outputExt = targetFormat.ToLower().Replace("в ", ".").Trim();
string outputPath = Path.Combine(outputDir, name + outputExt);
// 1. КАРТИНКИ
if (imageExt.Contains(ext))
{
using (var img = new MagickImage(input))
{
if (outputExt == ".jpg" || outputExt == ".jpeg") img.Format = MagickFormat.Jpeg;
else if (outputExt == ".png") img.Format = MagickFormat.Png;
else if (outputExt == ".webp") img.Format = MagickFormat.WebP;
else if (outputExt == ".bmp") img.Format = MagickFormat.Bmp;
img.Write(outputPath);
}
}
// 2. МЕДИА (ВИДЕО/АУДИО) - Исправленный метод
else if (mediaExt.Contains(ext))
{
// Используем Arguments для обхода ошибки CS7036
FFMpegArguments
.FromFileInput(input)
.OutputToFile(outputPath, overwrite: true, options => options.WithSpeedPreset(Speed.Fast))
.ProcessSynchronously();
}
}
}
}