Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
marihachi opened this issue Jun 2, 2018 · 2 comments
Open

Comments

@marihachi
Copy link
Contributor

No description provided.

@marihachi marihachi changed the title 極端にデカい画像をリサイズする 極端にデカい画像をリサイズして表示・投稿する Jun 2, 2018
@marihachi
Copy link
Contributor Author

marihachi commented Jun 3, 2018

書いてみたけど頭悪そう 🤔

// リサイズ処理
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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants