用visual studio完成bmp图片显示及图像处理
发布网友
发布时间:2022-09-30 00:58
我来回答
共1个回答
热心网友
时间:2024-12-02 14:27
假设页面有按钮BtnShowImage,图片显示控件pbxShow ,BtnShowImage_Click
为BtnShowImage按钮的Click事件 则如下代码可以实现选择图片文件显示图片
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
private void BtnShowImage_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = "c:\\";
openFileDialog.Filter = @"图像文件(JPeg, Gif)|*.jpg;*.jpeg;*.gif;*.bmp;*.png| JPeg 图像文件(*.jpg;*.jpeg)"
+ "|*.jpg;*.jpeg |GIF 图像文件(*.gif)|*.gif |BMP图像文件(*.bmp)|*.bmp|Png图像文件(*.png)"
+ "| *.png ";
openFileDialog.RestoreDirectory = true;
openFileDialog.FilterIndex = 1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
var fName = openFileDialog.FileName;
Image img = Image.FromFile(fName);
this.pbxShow.Image = img;
}
}