OpenFileDialog pOpenFileDialog = new OpenFileDialog();
pOpenFileDialog.Filter = "JPEG(*.jpg;*.jpeg;*.gif;*.png;*.bmp)|*.jpg;*.jpeg;*.gif;*.png;*.bmp|所有文件|*.*";
pOpenFileDialog.RestoreDirectory = true;
pOpenFileDialog.FilterIndex = 1;
if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
{
string strPath = pOpenFileDialog.FileName;
//pictureEdit1.Image = Image.FromFile(strPath);
Bitmap bmPic = new Bitmap(strPath);
Point ptLoction = new Point(bmPic.Size);
if (ptLoction.X > pictureEdit1.Size.Width || ptLoction.Y > pictureEdit1.Size.Height)
{
//图像框的停靠方式
pictureEdit1.Dock = DockStyle.Fill;
//图像充滿图像框,並且图像維持比例
pictureEdit1.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;
}
else
{
//图像在图像框置中
pictureEdit1.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.StretchHorizontal;
}
//LoadAsync:非同步转入图像
pictureEdit1.LoadAsync(strPath);
}
pOpenFileDialog.Filter = "JPEG(*.jpg;*.jpeg;*.gif;*.png;*.bmp)|*.jpg;*.jpeg;*.gif;*.png;*.bmp|所有文件|*.*";
pOpenFileDialog.RestoreDirectory = true;
pOpenFileDialog.FilterIndex = 1;
if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
{
string strPath = pOpenFileDialog.FileName;
//pictureEdit1.Image = Image.FromFile(strPath);
Bitmap bmPic = new Bitmap(strPath);
Point ptLoction = new Point(bmPic.Size);
if (ptLoction.X > pictureEdit1.Size.Width || ptLoction.Y > pictureEdit1.Size.Height)
{
//图像框的停靠方式
pictureEdit1.Dock = DockStyle.Fill;
//图像充滿图像框,並且图像維持比例
pictureEdit1.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;
}
else
{
//图像在图像框置中
pictureEdit1.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.StretchHorizontal;
}
//LoadAsync:非同步转入图像
pictureEdit1.LoadAsync(strPath);
}