using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace CSTest { public partial class FormMain : Form { public string num { get; internal set; } public string name { get; internal set; } public int age { get; internal set; } public string sex { get; internal set; } public string filepath { get; internal set; } public FormMain() { InitializeComponent(); } public delegate void MyInvoke();//定义一个委托事件 private void buttonOpen_Click(object sender, EventArgs e) { //myView.OpenDicom(); Thread newThread = new Thread(new ThreadStart(myView.Open)); newThread.SetApartmentState(ApartmentState.STA); newThread.Start(); } private void buttonRotateCW_Click(object sender, EventArgs e) { if (myView.IsImageOpen()) myView.RotateFilp(CSCustomDisplay.CustomView.eRotateFlipDirection.eRotateCW); } private void buttonRotateCCW_Click(object sender, EventArgs e) { if (myView.IsImageOpen()) myView.RotateFilp(CSCustomDisplay.CustomView.eRotateFlipDirection.eRotateCCW); } private void buttonRotate180_Click(object sender, EventArgs e) { if (myView.IsImageOpen()) myView.RotateFilp(CSCustomDisplay.CustomView.eRotateFlipDirection.eRotate180); } private void buttonFlipTB_Click(object sender, EventArgs e) { if (myView.IsImageOpen()) myView.RotateFilp(CSCustomDisplay.CustomView.eRotateFlipDirection.eFlipTB); } private void buttonFlipLR_Click(object sender, EventArgs e) { if (myView.IsImageOpen()) myView.RotateFilp(CSCustomDisplay.CustomView.eRotateFlipDirection.eFlipLR); } string dcmfile; private void FormMain_Load(object sender, EventArgs e) { if(btn_ok.Visible==false) { try { WebClient wc = new WebClient(); wc.DownloadFile(ConfigurationManager.AppSettings["ReportUrl"] + filepath, Application.StartupPath + "\\down_dicom.dcm"); filepath = Application.StartupPath + "\\down_dicom.dcm"; } catch(Exception ex) { MessageBox.Show(ex.Message); return; } } else { filepath = ConfigurationManager.AppSettings["imagePath"] + filepath; //MessageBox.Show(filepath); } if (!string.IsNullOrEmpty(filepath) && File.Exists(filepath)) { dcmfile = filepath; myView.ReadDicom(filepath); } } public object data { get; set; } private void btn_ok_Click(object sender, EventArgs e) { using(Bitmap bm=myView.getImg()) { if(bm==null) { data = new { imageBase64 = "", jl = "", sj = "", bgbase64 = "" }; } else { FileStream ms = new FileStream(Application.StartupPath+"\\dicom.jpg",FileMode.Create); bm.Save(ms, ImageFormat.Jpeg); ms.Close(); ms.Dispose(); List imagesbase64 = new List(); //imagesbase64.Add(Convert.ToBase64String(ms1.ToArray())); //ms1.Dispose(); WebClient wc = new WebClient(); byte[] resp = wc.UploadFile(ConfigurationManager.AppSettings["ReportUrl"] + "result/uploadfile", dcmfile); string resstr = System.Text.Encoding.UTF8.GetString(resp); dynamic d= Newtonsoft.Json.JsonConvert.DeserializeObject(resstr); imagesbase64.Add(d.msg.ToString()); resp = wc.UploadFile(ConfigurationManager.AppSettings["ReportUrl"] + "result/uploadfile", Application.StartupPath + "\\dicom.jpg"); resstr = System.Text.Encoding.UTF8.GetString(resp); dynamic d1 = Newtonsoft.Json.JsonConvert.DeserializeObject(resstr); data = new { imageBase64 = imagesbase64, jl = "", sj = "", bgbase64 = d1.msg.ToString() }; ms.Dispose(); } } this.Close(); } internal void hideok() { //throw new NotImplementedException(); btn_ok.Hide(); } private void FormMain_FormClosing(object sender, FormClosingEventArgs e) { try { File.Delete(Application.StartupPath + "\\down_dicom.dcm"); } catch { } } } }