zoukankan      html  css  js  c++  java
  • C# 调用 系统自带图片工具 查看/编辑图片

    private void btnEdit_Click(object sender, EventArgs e)
    {
    ViewOrignalImage(pictureBox1.Image);
    }

    /// 查看原图
    /// </summary>
    /// <param name="image"></param>
    private void ViewOrignalImage(Image image)
    {
    ////查看原图
    //try
    //{
    // var tempFilePath = string.Empty;
    // if (image != null)
    // {
    // tempFilePath = System.Windows.Forms.Application.StartupPath + "\temp.png";
    // Bitmap bm = new Bitmap(image);
    // bm.Save(tempFilePath);
    // bm.Dispose();
    // }
    // //建立新的系统进程
    // System.Diagnostics.Process process = new System.Diagnostics.Process();

    // //设置进程运行参数,这里以最大化窗口方法显示图片。
    // //process.StartInfo.Arguments = "rundl132.exe C://WINDOWS//system32//shimgvw.dll,ImageView_Fullscreen";

    // ////此项为是否使用Shell执行程序,因系统默认为true,此项也可不设,但若设置必须为true
    // //process.StartInfo.UseShellExecute = true;

    // //此处可以更改进程所打开窗体的显示样式,可以不设
    // process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    // process.Start();
    // process.Close();
    //}
    //catch
    //{

    //}


    var tempFilePath = string.Empty;
    if (image != null)
    {
    tempFilePath = System.Windows.Forms.Application.StartupPath + "\"+ txtFPath.Text;
    Bitmap bm = new Bitmap(image);
    bm.Save(tempFilePath);
    bm.Dispose();
    }

    Process process = new Process();
    process = Process.Start("mspaint.exe", tempFilePath);
    int processId = process.Id;
    process.EnableRaisingEvents = true; //必须设置此项,否则事件调用无效
    process.Exited += new EventHandler(Process_Exited);
    }

    private void Process_Exited(object sender, EventArgs e)
    {
    string strPath = Application.StartupPath + "\" + txtFPath.Text;
    string[] _strtemp1 = strPath.ToString().Split('\');
    string _temp = _strtemp1[_strtemp1.Length - 1];
    try
    {
    //创建文件流,path参数是文件路径
    FileStream fs = new FileStream(strPath.ToString(), FileMode.Open);
    int streamLength = (int)fs.Length; //获取文件流的长度。
    byte[] image = new byte[streamLength]; //声明字节数组,用于保存图片文件
    fs.Read(image, 0, streamLength); //把图片文件转换成为字节数组保存
    fs.Close();
    //插入Sql语句,@img是Sql语句参数。 // DrawNum='" + txtDrawNum.Text + "' and
    string sql = String.Format("UPDATE Bom SET FPathImg=@img,FPath='{0}' where Ancestor='{1}' and Ver='{2}'", _temp, txtAncestor.Text, txtVer.Text);
    W1.DCImg(sql, image, "Sys");
    //显示图片


    MemoryStream mystream = new MemoryStream(image);
    //用指定的数据流来创建一个image图片

    System.Drawing.Image img = System.Drawing.Image.FromStream(mystream, true);
    this.pictureBox1.Image = img;
    mystream.Close();

    }
    catch
    {
    MessageBox.Show("截面图文件编辑失败!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    File.Delete(Application.StartupPath + "\" + txtFPath.Text);
    }

    public static AutomationElement FindWindowByProcessId(int processId)
    {

    //AutomationElement element = FindWindowByProcessId(processId);
    //System.Windows.Forms.SendKeys.SendWait("^s"); //发送 Ctrl + s 键
    //System.Windows.Forms.SendKeys.SendWait("%{F4}"); // 发送 Alt + F4 键

    AutomationElement targetWindow = null;
    int count = 0;
    try
    {
    Process p = Process.GetProcessById(processId);
    targetWindow = AutomationElement.FromHandle(p.MainWindowHandle);
    return targetWindow;
    }
    catch (Exception ex)
    {
    count++;
    StringBuilder sb = new StringBuilder();
    string message = sb.AppendLine(string.Format("Target window is not existing.try #{0}", count)).ToString();
    if (count > 5)
    {
    throw new InvalidProgramException(message, ex);
    }
    else
    {
    return FindWindowByProcessId(processId);
    }
    }
    }

  • 相关阅读:
    Android Fragment(一)
    Android github上的好的开源项目汇总
    Android ScrollView 嵌套ListView的替代方案
    Android cannot be cast to android.app.Fragment
    js css加时间戳
    WPF无边框实现拖动效果
    分析器错误消息: 未能加载类型
    微信红包功能(含示例demo)
    ABP缓存示例
    微信白名单配置与检验
  • 原文地址:https://www.cnblogs.com/limitpjz/p/15429563.html
Copyright © 2011-2022 走看看