русский

ИИ для программиста?

28.08.24 22:03
Re: ИИ для программиста?
 
AlexNek патриот
AlexNek
in Antwort alex445 28.08.24 20:53
Попробуйте заставить его сделать бесшовную текстуру (seamless texture) из просто фотографии

Для начала, как это сделать из просто любой фотографии я не имею представления. Это должна быть спец. фото с какой-то структурой

Ну и это мне абсолютно не нужно. Но ИИ что-то выдал, насколько правильно не имею понятия.

using System.Drawing;

class Program
{
    static void Main()
    {
        Bitmap originalImage = new Bitmap("path_to_your_image.jpg");
        int width = originalImage.Width;
        int height = originalImage.Height;

        Bitmap offsetImage = new Bitmap(width, height);
        using (Graphics g = Graphics.FromImage(offsetImage))
        {
            g.DrawImage(originalImage, new Rectangle(0, 0, width / 2, height / 2), new Rectangle(width / 2, height / 2, width / 2, height / 2), GraphicsUnit.Pixel);
            g.DrawImage(originalImage, new Rectangle(width / 2, 0, width / 2, height / 2), new Rectangle(0, height / 2, width / 2, height / 2), GraphicsUnit.Pixel);
            g.DrawImage(originalImage, new Rectangle(0, height / 2, width / 2, height / 2), new Rectangle(width / 2, 0, width / 2, height / 2), GraphicsUnit.Pixel);
            g.DrawImage(originalImage, new Rectangle(width / 2, height / 2, width / 2, height / 2), new Rectangle(0, 0, width / 2, height / 2), GraphicsUnit.Pixel);
        }

        Bitmap seamlessTexture = new Bitmap(width, height);
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                Color originalColor = offsetImage.GetPixel(x, y);
                int blendFactor = Math.Min(Math.Min(x, width - x), Math.Min(y, height - y));
                int alpha = 255 - blendFactor * 255 / (width / 2);
                Color blendedColor = Color.FromArgb(alpha, originalColor.R, originalColor.G, originalColor.B);
                seamlessTexture.SetPixel(x, y, blendedColor);
            }
        }

        seamlessTexture.Save("path_to_save_seamless_texture.png", System.Drawing.Imaging.ImageFormat.Png);
    }
}

 

Sprung zu