トップ回答者
メッセージボックスのアイコンを大きくしたい

質問
-
いつもお世話になっております。
C#2010で開発しています。
メッセージボックスの文字やアイコンを大きくしたいと思い、独自のメッセージボックスを作成しています。アイコンは次のようにプログラムして表示しています。this.pictureBox1.Image = SystemIcons.Error.ToBitmap();pictureBox1のサイズは80×80で、SizeModeはZoomにしています。この場合、エラーアイコンは表示されるのですが、指定したアイコンが小さいようで、アイコンがカクカクして表示されてしまいます。次図のイメージです。Windows標準のアイコンを、OSの種類に合わせて表示したいため、アイコンファイルを埋め込んで対応することはしたくないと思っております。(C:\Program Files\Microsoft Visual Studio 10.0\Common7\VS2010ImageLibrary\1041\VS2010ImageLibrary.zipのファイルは利用したくないということです。)何か良い解決策をご存知でしたら教えて頂けないでしょうか?よろしくお願い致します。
回答
-
private Image GetResizeIconImage(System.Drawing.Icon icon, Size controlSize) { Image sourceImage = icon.ToBitmap(); decimal rate = controlSize.Width / sourceImage.Size.Width; if (rate > controlSize.Height / sourceImage.Size.Height) { rate = controlSize.Height / sourceImage.Size.Height; } Rectangle rect = default(Rectangle); rect.Width = Convert.ToInt32(sourceImage.Size.Width * rate); rect.Height = Convert.ToInt32(sourceImage.Size.Height * rate); Bitmap destImage = new Bitmap(rect.Width, rect.Height); Graphics g = Graphics.FromImage(destImage); g.InterpolationMode = Drawing2D.InterpolationMode.High; g.DrawImage(sourceImage, rect); return destImage; }
C#版・・・- 回答としてマーク コンドル 2012年1月7日 7:35
-
補間すれば多少はカクカク感が緩和されるはずです。具体的には
以下のページが参考になりませんか?画像を高品質に拡大/縮小するには?
http://www.atmarkit.co.jp/fdotnet/dotnettips/023resize/resize.html補間モードを使用したスケーリング時の画質の制御
http://msdn.microsoft.com/ja-jp/library/aa701031(v=vs.71).aspxInterpolationMode 列挙体
http://msdn.microsoft.com/ja-jp/library/system.drawing.drawing2d.interpolationmode.aspx- 回答としてマーク コンドル 2012年1月7日 7:35
すべての返信
-
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom pictureBox1.Image = SystemIcons.Error.ToBitmap
今は上記の様になっている部分を、Dim sourceImage As Image = SystemIcons.Error.ToBitmap Dim rate As Decimal = pictureBox1.Size.Width / sourceImage.Size.Width If rate > pictureBox1.Size.Height / sourceImage.Size.Height Then rate = pictureBox1.Size.Height / sourceImage.Size.Height End If Dim rect As Rectangle rect.Width = CInt(sourceImage.Size.Width * rate) rect.Height = CInt(sourceImage.Size.Height * rate) Dim destImage As New Bitmap(rect.Width, rect.Height) Dim g As Graphics = Graphics.FromImage(destImage) g.InterpolationMode = Drawing2D.InterpolationMode.High g.DrawImage(sourceImage, rect) pictureBox1.SizeMode = PictureBoxSizeMode.Zoom pictureBox1.Image = destImage
この様にしてみて下さい。こちらで試してみた所、中々良い線いってるかと・・・ -
個人的には、
Private Function GetResizeIconImage(ByVal icon As System.Drawing.Icon, ByVal controlSize As Size) As Image Dim sourceImage As Image = icon.ToBitmap Dim rate As Decimal = controlSize.Width / sourceImage.Size.Width If rate > controlSize.Height / sourceImage.Size.Height Then rate = controlSize.Height / sourceImage.Size.Height End If Dim rect As Rectangle rect.Width = CInt(sourceImage.Size.Width * rate) rect.Height = CInt(sourceImage.Size.Height * rate) Dim destImage As New Bitmap(rect.Width, rect.Height) Dim g As Graphics = Graphics.FromImage(destImage) g.InterpolationMode = Drawing2D.InterpolationMode.High g.DrawImage(sourceImage, rect) Return destImage End Function
こんなFunctionを作っておいて、this.pictureBox1.Image = GetResizeIconImage(SystemIcons.Error, this.pictureBox1.Size)
みたいに呼びたいですね。
・・・今気付いた・・・C#が良かったっぽい
-
private Image GetResizeIconImage(System.Drawing.Icon icon, Size controlSize) { Image sourceImage = icon.ToBitmap(); decimal rate = controlSize.Width / sourceImage.Size.Width; if (rate > controlSize.Height / sourceImage.Size.Height) { rate = controlSize.Height / sourceImage.Size.Height; } Rectangle rect = default(Rectangle); rect.Width = Convert.ToInt32(sourceImage.Size.Width * rate); rect.Height = Convert.ToInt32(sourceImage.Size.Height * rate); Bitmap destImage = new Bitmap(rect.Width, rect.Height); Graphics g = Graphics.FromImage(destImage); g.InterpolationMode = Drawing2D.InterpolationMode.High; g.DrawImage(sourceImage, rect); return destImage; }
C#版・・・- 回答としてマーク コンドル 2012年1月7日 7:35
-
補間すれば多少はカクカク感が緩和されるはずです。具体的には
以下のページが参考になりませんか?画像を高品質に拡大/縮小するには?
http://www.atmarkit.co.jp/fdotnet/dotnettips/023resize/resize.html補間モードを使用したスケーリング時の画質の制御
http://msdn.microsoft.com/ja-jp/library/aa701031(v=vs.71).aspxInterpolationMode 列挙体
http://msdn.microsoft.com/ja-jp/library/system.drawing.drawing2d.interpolationmode.aspx- 回答としてマーク コンドル 2012年1月7日 7:35