Work with C#image

Asked

Viewed 743 times

0

I have two images:

Escada

menino

At runtime, I need to join the two images together. You can determine the position of the doll on the ladder. Both images are on disk.

The result would be images like these in Base64:

inserir a descrição da imagem aqui

Are there libraries that can help me with this? What are the best?

Note: I am in an Asp.Net MVC . Net Framework 4 project

  • Just take the MARGIN properties of the images and change them

1 answer

1


Use as follows:

var Ima = Image.FromFile(@"C:\Users\PC\Desktop\kOWnj.jpg");
var Imb = Image.FromFile(@"C:\Users\PC\Desktop\AlaDL.jpg");
Image IMGfinal = MergeTwoImages(Ima, Imb);

I’ve done with both images:

public Bitmap MergeTwoImages(Image ImagemA, Image ImagemB)
        {
            if (ImagemA == null)
            {
                throw new ArgumentNullException("ImagemA");
            }

            if (ImagemB == null)
            {
                throw new ArgumentNullException("ImagemB");
            }

            int outputImageWidth = ImagemA.Width + ImagemB.Width;
            int outputImageHeight = ImagemA.Height + ImagemB.Height;

            int imagemAx = 0;
            int imagemAy = 100;

            int imagemBx = 140;
            int imagemBy = -10;

            Bitmap outputImage = new Bitmap(outputImageWidth, outputImageHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            using (Graphics graphics = Graphics.FromImage(outputImage))
            {
                graphics.FillRectangle(new SolidBrush(Color.White), new Rectangle(new Point(), new Size(outputImageWidth,outputImageHeight))); //fundo branco
                graphics.DrawImage(ImagemA, new Rectangle(new Point(imagemAx, imagemAy), ImagemA.Size), new Rectangle(new Point(), ImagemA.Size), GraphicsUnit.Pixel);//imagem 1
                graphics.DrawImage(ImagemB, new Rectangle(new Point(imagemBx, imagemBy), ImagemB.Size), new Rectangle(new Point(), ImagemB.Size), GraphicsUnit.Pixel);//imagem 2
            }

            return outputImage;
        }

You also find other ways in this link.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.