サーバーから受信した画像を表示するためにpictureBoxを使用していますが、問題は、コンパクトフレームワークの画像ボックスに3つのサイズモードしかないことです。
StretchImage、Normal、CenterImage
私が取得している写真は一般的にサイズが大きいので、StrethImageモードを使用する必要があります。ただし、アスペクト比は維持されるため、表示される画像は歪んでしまいます。
それで、とにかく彼らはこの問題から抜け出すのですか?
サーバーから受信した画像を表示するためにpictureBoxを使用していますが、問題は、コンパクトフレームワークの画像ボックスに3つのサイズモードしかないことです。
StretchImage、Normal、CenterImage
私が取得している写真は一般的にサイズが大きいので、StrethImageモードを使用する必要があります。ただし、アスペクト比は維持されるため、表示される画像は歪んでしまいます。
それで、とにかく彼らはこの問題から抜け出すのですか?
ついに私はここにある私の質問に対する答えを見つけました-----
float actualHeight = myImg.Height;
float actualWidth = myImg.Width;
float imgRatio = actualWidth / actualHeight;
float maxRatio = (float)this.Width / this.Height;
if(imgRatio!=maxRatio)
{
if (imgRatio < maxRatio)
{
imgRatio = this.Height / actualHeight;
actualWidth = imgRatio * actualWidth;
actualHeight = this.Height;
}
else
{
imgRatio = this.Width / actualWidth;
actualHeight = imgRatio * actualHeight;
actualWidth = this.Width;
}
}
pictureBox.Size=new Size((int)actualWidth,(int)actualHeight);
pictureBox.Location = new Point((int)((this.Width - actualWidth) / 2), (int)((this.Height - actualHeight) / 2));
ただし、これを行う前に、画像ボックスのサイズモードをstretchImageのままにしてください