How to add a border to an image with C#

Asked

Viewed 401 times

1

I would like to take an image and add a border at the top of the image (BMP). For what I researched I need

  1. load the image into an object
  2. create a rectangle object
  3. add the rectangle to the image

but I never worked with image in C# :(

Example: That image

inserir a descrição da imagem aqui

to look like this

inserir a descrição da imagem aqui

  • See if this can help you http://stackoverflow.com/a/14593261/2221388

  • WinForms or WPF?

  • I’m doing a windows service, this method I’ll put in a library.

  • @Pablovargas This example the border overlays the image, I want to add a border.

  • @Fellipe Do you want to insert this border "inside" the image? That is, edit the bmp file itself?

  • @Ismael was an option, but I decided to create another file by concatenating two images. I left a default border to be added in the images.

Show 1 more comment

2 answers

0

Hello, would just change the px sizes of the border no?!

border-image-width: 10px 10px 10px 10px;
(top) (right) (bottom) (left)

0


I was able to solve this problem by concatenating two images.

            Image principal = Image.FromFile(@"ImagemPrincipal.jpg");
            Image logo = Image.FromFile(@"ImagemHeader.jpg");

            int imagemSaida_Width = principal.Width;
            int imagemSaida_Height = principal.Height + logo.Height;

            var imagemSaida = new Bitmap(imagemSaida_Width, imagemSaida_Height);

            using (principal)
            {
                using (imagemSaida)
                {
                    using (var canvas = Graphics.FromImage(imagemSaida))
                    {

                        canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        // Definir plano de funda do arquivo de saida como Branco
                        canvas.Clear(Color.White);

                        // Adicionar o logo no arquivo de saida
                        canvas.DrawImage(logo, 0, 0);

                        // Adidionar principal no arquivo de saida
                        canvas.DrawImage(exame, 0, logo.Height);
                        canvas.Save();
                    }
                    imagemSaida.Save("ImagePrincipalComLogo.jpg");
                }
            }

Browser other questions tagged

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