描画先の範囲に合せて、画像の合成
左右・上下に空きがないよう、Web 画像を拡大・縮小して必要な範囲を描画します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dim dst = New Rectangle(754, 18, 1110, 807) ' 描画先の位置・大きさ | |
Dim src = New Rectangle(0, 0, webBmp.Width, webBmp.Height) ' 参照画像の位置・大きさ | |
If dst.Width / dst.Height < webBmp.Width / webBmp.Height Then | |
Dim w = dst.Width / (dst.Height / webBmp.Height) | |
src.X = Convert.ToInt32((webBmp.Width - w) / 2) | |
src.Width = Convert.ToInt32(w) | |
Else | |
Dim h = dst.Height / (dst.Width / webBmp.Width) | |
src.Y = Convert.ToInt32((webBmp.Height - h) / 2) | |
src.Height = Convert.ToInt32(h) | |
End If | |
Dim wallBmp = New Bitmap(System.IO.Path.Combine(Server.MapPath("./"), "wallpaper.png")) | |
Dim outBmp = New Bitmap(wallBmp.Width, wallBmp.Height) | |
Using g = Graphics.FromImage(outBmp) | |
g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality | |
g.DrawImage(webBmp, dst, src, GraphicsUnit.Pixel) | |
g.DrawImage(wallBmp, 0, 0, wallBmp.Width, wallBmp.Height) | |
End Using |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment