开发者

drawing image to bigger bitmap [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜