drawing image to bigger bitmap [closed]
Basically I want to stretch smaller image (i.e. 300x300 to bigger one i.e. 500x500) without space or black background.
I have a bitmap (let's say width 500px, and height 500px). How to draw another (smaller) image on that bitmap so it takes whole bitmap?
I already know how to create bitmap (i.e. var bitmap = new Bitmap(500, 500);
开发者_如何学编程) and get the image - it can be loaded from file (i.e. var image = Image.FromFile(...);
) or obtained from some other source.
See the documentation for Graphics.DrawImage. You can specify source and destination rectangles.
Example code:
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);
}
To use code make sure to add reference to System.Drawing assembly and add using System.Drawing
to the file.
You could try using the following:
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;
}
And choose from one of the available InterpolationModes.
精彩评论