Drawing an image into a larger bitmap

Basically, I want to stretch a smaller image (i.e. 300x300 to a larger one, i.e. 500x500) with no space or black background.

I have a bitmap (for example, a width of 500 pixels and a height of 500 pixels). How to draw another (smaller) image on this bitmap so that it accepts whole bitmaps?

I already know how to create a bitmap image (i.e. var bitmap = new Bitmap(500, 500);) and get an image - it can be downloaded from a file (i.e. var image = Image.FromFile(...);) or obtained from another source.

+5
source share
2 answers

Graphics.DrawImage. .

:

Image i = Image.FromFile(fileName); // This is 300x300
Bitmap b = new Bitmap(500, 500);

using(Graphics g = Graphics.FromImage(b))
{
    g.DrawImage(i, 0, 0, 500, 500);
}

, System.Drawing using System.Drawing .

+14

:

public Image ImageZoom(Image image, Size newSize)
{
    var bitmap = new Bitmap(image, newSize.Width, newSize.Height);
    using (var g = Graphics.FromImage(bitmap))
    {
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
    }

    return bitmap;
}

InterpolationModes.

+1

All Articles