문제

I need some help cropping and resizing images using CSharp.net. My goal here is to take an image and reduce it to 50px by 50px. The following code I found here will do that, however it's scaling the image as well. Ideally I want to scale the image down to as close to 50px by 50px as possible and then remove the parts of the image that are outside 50px by 50px.

public Image ResizeImage(Image img, int width, int height)
{
    Bitmap b = new Bitmap(width, height);
    using (Graphics g = Graphics.FromImage((Image)b))
    {
        g.DrawImage(img, 0, 0, width, height);
    }

    return (Image)b;
}
도움이 되었습니까?

해결책

Maybe you can find answer in this question: Best resize and or crop logic

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top