How to create a track extending an Image in c#

Asked

Viewed 144 times

1

I am developing a method to add a purple stripe to the images that are processed in my application. I’m using c# to draw in the image, currently I do so:

using (Image image = Image.FromFile(originalFilePath))
{
    Graphics imageGraphics = Graphics.FromImage(image);
    Rectangle FooterRectangle = new Rectangle(0, image.Height - 50, image.Width, 50); // image.height = 450px   image.width = 450px
    SolidBrush footerBrush = new SolidBrush(Color.FromArgb(189, 5, 59));
    imageGraphics.FillRectangle(footerBrush, FooterRectangle);
}

The result is this(Ignore watermark and text, focus on purple band):inserir a descrição da imagem aqui

Until then beauty, the problem is, the track is superimposing the image, I need it to increase the height. For example, the image has 450px x x 450px need to get 450px x x 500px or I will not be cutting a part of the photo. There is a way instead of about incrementing the height of the photo?

1 answer

1


You must create a new image, with larger size, and redesign your image from above:

using (Image image = Image.FromFile(originalFilePath))
{
    System.Drawing.Bitmap novaImagem = new System.Drawing.Bitmap(image.Width, image.Height + 50); //sendo 50 o a altura da sua 'faixa'

    using (Graphics g = Graphics.FromImage(novaImagem)) //o Graphics vem da nova imagem
    {
        g.Clear(Color.FromArgb(189, 5, 59)); //"limpo" a nova imagem, e deixo ela toda na cor desejada (isso não é roxo, rsrs)

        g.DrawImage(image, new Rectangle(0,0,image.Width,image.Height));
        //Aqui, se quiser, você pode colocar o DrawString e escrever o texto...
    }

    return novaImagem;
}
  • I had solved basically the same ! Thanks +1

  • Isn’t it purple? kkkkkkkkkkk is pink? hahaha

  • 1

    not kkkk... ta more like red... purple is the image of my profile =] vlww

Browser other questions tagged

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