using Gtk; using Cairo; using System; class SharpApp : Window { private ImageSurface surface; private int imageWidth; // Ширина зображення private int imageHeight;// Висота зображення private int gap; // Відступ по вертикалі між зображеннями public SharpApp() : base("Віддзеркалення") { try {surface = new ImageSurface("image.png");} catch { Console.WriteLine("Файлу зображення не знайдено"); Environment.Exit(1); } imageWidth = surface.Width; imageHeight = surface.Height; gap = 1; SetDefaultSize(imageWidth, 2*imageHeight+gap); SetPosition(WindowPosition.Center); DeleteEvent += delegate {Application.Quit();}; DrawingArea darea = new DrawingArea(); darea.ExposeEvent += OnExpose; Add(darea); ShowAll(); } void OnExpose(object sender, ExposeEventArgs args) { DrawingArea area = (DrawingArea) sender; Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow); int height = Allocation.Height; // Заповнити тло плавним ґрадієнтом від чорного до темно-сірого LinearGradient lg = new LinearGradient(0,0,0,height*3); lg.AddColorStop(0, new Color(0, 0, 0, 1)); lg.AddColorStop(height, new Color(0.0, 0.2, 0.2,1)); cr.SetSource(lg); cr.Paint(); cr.SetSourceSurface(surface, 0, 0); cr.Paint(); double alpha = 0.9; // Початкова прозорість double step = 1.0 / imageHeight; // Величина зміни прозорості за 1 px по вертикалі cr.Translate(0, 2 * imageHeight + gap); // Перенесення зображення cr.Scale(1, -1); // Симетрія відносно горзонталі for (int i = 0; i < imageHeight; i++) // Надання прозорості, змінної по вертикалі { cr.Rectangle(new Rectangle(0, imageHeight-i, imageWidth, 1)); cr.Clip(); cr.SetSource(surface, 0, 0); cr.PaintWithAlpha(alpha-=step); cr.ResetClip(); } ((IDisposable) cr.GetTarget()).Dispose();// Прибирання сміття ((IDisposable) cr).Dispose(); } public static void Main() { Application.Init(); new SharpApp(); Application.Run(); } }