private void DisplayImage() { if (ImageCurrent == null) //Likely the user canceled out of downloading { return; } try { renderImage = ImageHelper.ApplyDocumentSettingsToImage(displayedDoc, ImageCurrent, ImageSettingFlags.CROP | ImageSettingFlags.COLORFUNCTION); if (renderImage == null) { imageZoom = 1; imageTranslation = new PointF(0, 0); } else { float matchWidth = PictureBox1.Width - 16; matchWidth = (matchWidth <= 0?1:matchWidth); float matchHeight = PictureBox1.Height - 16; matchHeight = (matchHeight <= 0?1:matchHeight); imageZoom = Math.Min(matchWidth / renderImage.Width, matchHeight / renderImage.Height); imageTranslation = new PointF(PictureBox1.Width / 2.0f, PictureBox1.Height / 2.0f); } zoomLevel = 0; zoomFactor = 1; } catch (Exception exception) { MessageBox.Show(Lan.g(this, exception.Message)); ImageCurrent = null; renderImage = null; } UpdatePictureBox(); }
private void butPickRxListImage_Click(object sender, EventArgs e) { if (!PrefC.AtoZfolderUsed) { MsgBox.Show(this, "This option is not supported with images stored in the database."); return; } FormImageSelect formIS = new FormImageSelect(); formIS.PatNum = PatCur.PatNum; formIS.ShowDialog(); if (formIS.DialogResult != DialogResult.OK) { return; } string patFolder = ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath()); Document doc = Documents.GetByNum(formIS.SelectedDocNum); if (!ImageStore.HasImageExtension(doc.FileName)) { MsgBox.Show(this, "The selected file is not a supported image type."); return; } textDocDateDesc.Text = doc.DateTStamp.ToShortDateString() + " - " + doc.Description.ToString(); if (BitmapOriginal != null) { BitmapOriginal.Dispose(); } BitmapOriginal = ImageStore.OpenImage(doc, patFolder); Bitmap bitmap = ImageHelper.ApplyDocumentSettingsToImage(doc, BitmapOriginal, ImageSettingFlags.ALL); pictBox.BackgroundImage = bitmap; resizePictBox(); }
/// <summary>This form will get the necessary images off disk so that it can control layout.</summary> public void SetImage(Document thisDocument, string displayTitle) { //for now, the document is single. Later, it will get groups for composite images/mounts. Text = displayTitle; displayedDoc = thisDocument; List <long> docNums = new List <long>(); docNums.Add(thisDocument.DocNum); string fileName = (string)Documents.GetPaths(docNums, ImageStore.GetPreferredAtoZpath())[0]; if (!File.Exists(fileName)) { MessageBox.Show(fileName + " could not be found."); return; } try { ImageCurrent = new Bitmap(fileName); renderImage = ImageHelper.ApplyDocumentSettingsToImage(thisDocument, ImageCurrent, //ContrDocs.ApplyDocumentSettingsToImage(thisDocument,ImageCurrent, ImageSettingFlags.CROP | ImageSettingFlags.COLORFUNCTION); if (renderImage == null) { imageZoom = 1; imageTranslation = new PointF(0, 0); } else { float matchWidth = PictureBox1.Width - 16; matchWidth = (matchWidth <= 0?1:matchWidth); float matchHeight = PictureBox1.Height - 16; matchHeight = (matchHeight <= 0?1:matchHeight); imageZoom = (float)Math.Min(matchWidth / renderImage.Width, matchHeight / renderImage.Height); imageTranslation = new PointF(PictureBox1.Width / 2.0f, PictureBox1.Height / 2.0f); } zoomLevel = 0; zoomFactor = 1; } catch (System.Exception exception) { MessageBox.Show(Lan.g(this, exception.Message)); ImageCurrent = null; renderImage = null; } UpdatePictureBox(); }
public void SetData(PatientDashboardDataEventArgs data, SheetField sheetField) { if (!IsNecessaryDataAvailable(data)) { return; } if (_docPatPicture == null) { return; } Document docForPat = data.ListDocuments.FirstOrDefault(x => x.DocNum == _docPatPicture.DocNum); if (sheetField != null && docForPat != null) { _docPatPicture = docForPat; using (Bitmap imageCopy = new Bitmap(data.BitmapImagesModule)) { SwapPatPicture(() => { using (Bitmap image = ImageHelper.ApplyDocumentSettingsToImage(_docPatPicture, imageCopy, ImageSettingFlags.ALL)) { return(ImageHelper.GetThumbnail(image, Math.Min(sheetField.Width, sheetField.Height))); } }); } } }
private void SaveAttachment() { Patient PatCur = Patients.GetPat(PatNum); //if(PatCur.ImageFolder=="") { // MsgBox.Show(this,"Invalid patient image folder."); // return; //} if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase) { MsgBox.Show(this, "Error. Not using AtoZ images folder."); return; } string patfolder = ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath()); //ODFileUtils.CombinePaths( //FormPath.GetPreferredImagePath(),PatCur.ImageFolder.Substring(0,1).ToUpper(),PatCur.ImageFolder); //if(!Directory.Exists(patfolder)) { // MsgBox.Show(this,"Patient folder not found in AtoZ folder."); // return; //} Document doc = Docs[gridMain.GetSelectedIndex()]; if (!ImageHelper.HasImageExtension(doc.FileName)) { MsgBox.Show(this, "Invalid file. Only images may be attached, no other file format."); return; } string oldPath = ODFileUtils.CombinePaths(patfolder, doc.FileName); Random rnd = new Random(); string newName = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString() + Path.GetExtension(oldPath); string attachPath = EmailAttaches.GetAttachPath(); string newPath = ODFileUtils.CombinePaths(attachPath, newName); if (CloudStorage.IsCloudStorage) { oldPath = oldPath.Replace("\\", "/"); newPath = newPath.Replace("\\", "/"); } try { if (ImageHelper.HasImageExtension(oldPath)) { if (doc.CropH != 0 || doc.CropW != 0 || doc.CropX != 0 || doc.CropY != 0 || doc.DegreesRotated != 0 || doc.IsFlipped || doc.WindowingMax != 0 || doc.WindowingMin != 0 || CloudStorage.IsCloudStorage) { //this does result in a significantly larger images size if jpg. A later optimization would recompress it. Bitmap bitmapold = null; if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ) { bitmapold = (Bitmap)Bitmap.FromFile(oldPath); Bitmap bitmapnew = ImageHelper.ApplyDocumentSettingsToImage(doc, bitmapold, ImageSettingFlags.ALL); bitmapnew.Save(newPath); } else if (CloudStorage.IsCloudStorage) { //First, download the file. FormProgress FormP = new FormProgress(); FormP.DisplayText = "Downloading Image..."; FormP.NumberFormat = "F"; FormP.NumberMultiplication = 1; FormP.MaxVal = 100; //Doesn't matter what this value is as long as it is greater than 0 FormP.TickMS = 1000; OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.DownloadAsync(patfolder , doc.FileName , new OpenDentalCloud.ProgressHandler(FormP.OnProgress)); FormP.ShowDialog(); if (FormP.DialogResult == DialogResult.Cancel) { state.DoCancel = true; return; } //Successfully downloaded, now do stuff with state.FileContent FormP = new FormProgress(); FormP.DisplayText = "Uploading Image for Claim Attach..."; FormP.NumberFormat = "F"; FormP.NumberMultiplication = 1; FormP.MaxVal = 100; //Doesn't matter what this value is as long as it is greater than 0 FormP.TickMS = 1000; OpenDentalCloud.Core.TaskStateUpload state2 = CloudStorage.UploadAsync(attachPath , newName , state.FileContent , new OpenDentalCloud.ProgressHandler(FormP.OnProgress)); FormP.ShowDialog(); if (FormP.DialogResult == DialogResult.Cancel) { state2.DoCancel = true; return; } //Upload was successful } } else { File.Copy(oldPath, newPath); } } else { File.Copy(oldPath, newPath); } ClaimAttachNew = new ClaimAttach(); ClaimAttachNew.DisplayedFileName = Docs[gridMain.GetSelectedIndex()].FileName; ClaimAttachNew.ActualFileName = newName; DialogResult = DialogResult.OK; } catch (FileNotFoundException ex) { MessageBox.Show(Lan.g(this, "File not found: ") + ex.Message); return; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void butPickRxListImage_Click(object sender, EventArgs e) { if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase) { MsgBox.Show(this, "This option is not supported with images stored in the database."); return; } FormImageSelect formIS = new FormImageSelect(); formIS.PatNum = PatCur.PatNum; formIS.ShowDialog(); if (formIS.DialogResult != DialogResult.OK) { return; } string patFolder = ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath()); Document doc = Documents.GetByNum(formIS.SelectedDocNum); if (!ImageStore.HasImageExtension(doc.FileName)) { MsgBox.Show(this, "The selected file is not a supported image type."); return; } textDocDateDesc.Text = doc.DateTStamp.ToShortDateString() + " - " + doc.Description.ToString(); if (BitmapOriginal != null) { BitmapOriginal.Dispose(); } if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ) { BitmapOriginal = ImageStore.OpenImage(doc, patFolder); } else { FormProgress FormP = new FormProgress(); FormP.DisplayText = "Downloading Image..."; FormP.NumberFormat = "F"; FormP.NumberMultiplication = 1; FormP.MaxVal = 100; //Doesn't matter what this value is as long as it is greater than 0 FormP.TickMS = 1000; OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.DownloadAsync(patFolder , doc.FileName , new OpenDentalCloud.ProgressHandler(FormP.OnProgress)); FormP.ShowDialog(); if (FormP.DialogResult == DialogResult.Cancel) { state.DoCancel = true; return; } else { using (MemoryStream ms = new MemoryStream(state.FileContent)) { BitmapOriginal = new Bitmap(ms); } } } Bitmap bitmap = ImageHelper.ApplyDocumentSettingsToImage(doc, BitmapOriginal, ImageSettingFlags.ALL); pictBox.BackgroundImage = bitmap; resizePictBox(); }
private void SaveAttachment() { Patient PatCur = Patients.GetPat(PatNum); //if(PatCur.ImageFolder=="") { // MsgBox.Show(this,"Invalid patient image folder."); // return; //} if (!PrefC.AtoZfolderUsed) { MsgBox.Show(this, "Error. Not using AtoZ images folder."); return; } string patfolder = ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath()); //ODFileUtils.CombinePaths( //FormPath.GetPreferredImagePath(),PatCur.ImageFolder.Substring(0,1).ToUpper(),PatCur.ImageFolder); //if(!Directory.Exists(patfolder)) { // MsgBox.Show(this,"Patient folder not found in AtoZ folder."); // return; //} Document doc = Docs[gridMain.GetSelectedIndex()]; if (!ImageHelper.HasImageExtension(doc.FileName)) { MsgBox.Show(this, "Invalid file. Only images may be attached, no other file format."); return; } string oldPath = ODFileUtils.CombinePaths(patfolder, doc.FileName); Random rnd = new Random(); string newName = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString() + Path.GetExtension(oldPath); string attachPath = EmailMessages.GetEmailAttachPath(); string newPath = ODFileUtils.CombinePaths(attachPath, newName); try { if (ImageHelper.HasImageExtension(oldPath)) { if (doc.CropH != 0 || doc.CropW != 0 || doc.CropX != 0 || doc.CropY != 0 || doc.DegreesRotated != 0 || doc.IsFlipped || doc.WindowingMax != 0 || doc.WindowingMin != 0) { //this does result in a significantly larger images size if jpg. A later optimization would recompress it. Bitmap bitmapold = (Bitmap)Bitmap.FromFile(oldPath); Bitmap bitmapnew = ImageHelper.ApplyDocumentSettingsToImage(doc, bitmapold, ImageSettingFlags.ALL); bitmapnew.Save(newPath); } else { File.Copy(oldPath, newPath); } } else { File.Copy(oldPath, newPath); } ClaimAttachNew = new ClaimAttach(); ClaimAttachNew.DisplayedFileName = Docs[gridMain.GetSelectedIndex()].FileName; ClaimAttachNew.ActualFileName = newName; DialogResult = DialogResult.OK; } catch (FileNotFoundException ex) { MessageBox.Show(Lan.g(this, "File not found: ") + ex.Message); return; } catch (Exception ex) { MessageBox.Show(ex.Message); } }