Legato-Dev / Legato-NowPlaying

Let's share information of songs are playing on AIMP to SNS.
Other
10 stars 2 forks source link

極端にデカい画像をリサイズして表示・投稿する #19

Open marihachi opened 6 years ago

marihachi commented 6 years ago

書いてみたけど頭悪そう :thinking:

// リサイズ処理
public Image Resize(Image image, int maxSide = 256)
{
    var longSide = image.Height > image.Width ? image.Height : image.Width;
    if (longSide <= maxSide)
        return image;
    var resizedWidth = maxSide;
    var resizedHeight = maxSide;
    if (image.Height > image.Width)
        resizedWidth *= image.Width / image.Height;
    else
        resizedHeight *= image.Height / image.Width;
    var resized = new Bitmap(resizedWidth, resizedHeight);
    var graph = Graphics.FromImage(resized);
    graph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    graph.DrawImage(image, 0, 0, resized.Width, resized.Height);
    return resized;
}
Asteriskx commented 5 years ago

実装はさておいて、Image 系ってコード煩雑になりがちだから仕方ないのでは()