Seasons.NET

ちょっとした技術ブログです

読み込んだアイコンとかの画像のサイズが矩形に収まっているかどうかの判定

Containってこういうことに使えるなぁ〜。

 1 
 2     string file    = "適当なパス.ico";
 3     FileInfo fi    = new FileInfo( file );
 4     Rectangle area = new Rectangle(new Point(0,0),new Size(32,32));
 5 
 6     Image ico      = Image.FromFile( file );
 7     if( area.Contains( new Rectangle( 0,0,ico.Width,ico.Height ) ) )
 8     {
 9         /* ここに来たらそのサイズ内に収まっている */
10     }