using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Reflection;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string strFilename = "";
OpenFileDialog dlgOpen = null;
try
{
dlgOpen = new OpenFileDialog();
dlgOpen.Filter = "All Image Files(*.*)|*.*";
if (dlgOpen.ShowDialog() == DialogResult.OK)
{
if (dlgOpen.FileName == "") return;
strFilename = dlgOpen.FileName;
pictureBox1.Image = Image.FromFile(strFilename);
this.SetImageSizeMode(pictureBox1);
}
}
catch (Exception ex)
{
MessageBox.Show("无法识别的图片格式(" + strFilename + ")\r\n" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (dlgOpen != null)
dlgOpen.Dispose();
dlgOpen = null;
}
}
/********************************************************************************************************/
private void SetImageSizeMode(PictureBox pImage)
{
if (pImage == null) retu
c# 图片截图
最新推荐文章于 2023-08-29 11:38:24 发布
这个C#程序实现了一个简单的图片截图功能。用户可以选择图片文件,然后在PictureBox中显示,通过鼠标选择截图区域,最后可以保存选定的截图。代码包括了图片加载、鼠标操作处理以及截图保存等关键步骤。
摘要由CSDN通过智能技术生成