private void rbnBtnAddImage_Click(object sender, EventArgs e) { if (picLstSerImage.Items.Count > 98) { MessageBox.Show("The series can contain 99 images at most" , "Adding Image Error" , MessageBoxButtons.OK , MessageBoxIcon.Error); return; } OFD.FileName = ""; OFD.InitialDirectory = "D:\\Brain Images"; OFD.Title = "Open an image file"; OFD.Filter = "JPEG Images (*.jpg)|*.jpg|Bitmap Images (*.bmp)|*.bmp"; OFD.ShowDialog(); Bitmap bmp; PictureListItem pItem; if (opr.ToLower() == "insert") //Insertion { string fname = ""; if (OFD.FileName != "") { foreach (string fileName in OFD.FileNames) { bmp = new Bitmap(fileName); fname = fileName.Substring(fileName.LastIndexOf('\\')).TrimStart('\\'); pItem = new PureComponents.EntrySet.Lists.PictureListItem( fname, bmp, true, fileName); picLstSerImage.Items.Add(pItem); } } } else //Modification { images_changed = true; string fname = ""; if (OFD.FileName != "") { foreach (string fileName in OFD.FileNames) { bmp = new Bitmap(fileName); fname = fileName.Substring(fileName.LastIndexOf('\\')).TrimStart('\\'); pItem = new PureComponents.EntrySet.Lists.PictureListItem( fname + " New", bmp, true, fileName); ImageRecord = new imageRecord( getUnusedImageID(int.Parse(rbnCboSeriesID.SelectedItem)).ToString(), null, fname, null); pItem.Value = ImageRecord; picLstSerImage.Items.Add(pItem); } } } }
public frmViewImage(string imagePath, imageRecord IR, databaseController DBC, string opr) { this.opr = opr; this.DBC = DBC; ImageRecord = IR; ContrastVal = 0; BrightnessVal = 0; bright_clicked = false; contrast_clicked = false; ImgPro = new imageProcessor(imagePath); ImgPath = imagePath; InitializeComponent(); }
private void viewAllImages() { try { DBC.CommandText = "SELECT * FROM IMAGE"; DataSet ds = DBC.ExecuteQuery(); DataSet sds; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string fname = ds.Tables[0].Rows[i].ItemArray[1].ToString(); string imgID = ds.Tables[0].Rows[i].ItemArray[0].ToString(); double sid = Math.Floor((double.Parse(imgID) / 100)); DBC.CommandText = "SELECT FolderPath FROM Series WHERE SID = " + sid.ToString() + " ;"; sds = DBC.ExecuteQuery(); if (sds.Tables[0].Rows.Count < 1) { return; } string imgFld = sds.Tables[0].Rows[0].ItemArray[0].ToString(); imgFld = (imgFld.EndsWith("\\")) ? imgFld : imgFld + "\\"; imgFld = (imgFld.StartsWith("\\")) ? imgFld : "\\" + imgFld; string imgpath = this.SC.SettingsList[0].TrimEnd('\\') + imgFld + fname; Bitmap bmp = new Bitmap(imgpath); PureComponents.EntrySet.Lists.PictureListItem pItem = new PureComponents.EntrySet.Lists.PictureListItem(fname, bmp, true, null); pItem.Tag = imgpath; imageRecord imgRecord = new imageRecord(imgID, null, fname, null); pItem.Value = imgRecord; picLstResults.Items.Add(pItem); } rbnMain.StatusBar.Text = "Database is connected."; rbnMain.StatusBar.Text = rbnMain.StatusBar.Text + " - - - - You have " + picLstResults.Items.Count + " images in the database"; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error viewing all images", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static async Task <List <string> > getPhotoIdsFromAlbum(string albumId) { using (var client = new HttpClient()) { string url = "https://api.imgur.com/3/album/" + albumId; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Client-ID", clientId); var imageResult = await client.GetAsync(url); using (MemoryStream inputStream = new MemoryStream()) { await imageResult.Content.CopyToAsync(inputStream); inputStream.Seek(0, SeekOrigin.Begin); var sr = new StreamReader(inputStream); string jsonstring = sr.ReadToEnd(); dynamic resultObj = JsonConvert.DeserializeObject(jsonstring); List <string> returnList = new List <string>(); List <imageRecord> records = new List <imageRecord>(); foreach (var imagerecord in resultObj.data.images) { imageRecord rec = new imageRecord(); rec.date = Convert.ToInt64(imagerecord.datetime); rec.link = imagerecord.link.ToString(); records.Add(rec); //returnList.Add(imagerecord.link.ToString()); } //returnList.Reverse(); returnList = records.OrderBy(x => x.date).Select(x => x.link).ToList(); return(returnList); } } }
private void rbnCboSeriesID_SelectedIndexChanged(object sender, EventArgs e) { try { int SID = int.Parse(rbnCboSeriesID.SelectedItem); if (DBC.IsConnected) { //Firstly check all categories of this series with ID : SID #region Check Categories DBC.CommandText = "SELECT CatID FROM Series_Cats where SID= " + SID.ToString() + " ;"; DataSet ds = DBC.ExecuteQuery(); if (ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < mListCats.Items.Count; i++) { mListCats.Items[i].CheckState = CheckState.Unchecked; } for (int i = 0; i < mListCats.Items.Count; i++) { for (int j = 0; j < ds.Tables[0].Rows.Count; j++) { if (mListCats.Items[i].Description == ds.Tables[0].Rows[j].ItemArray[0].ToString()) { mListCats.Items[i].CheckState = CheckState.Checked; } } } } #endregion //Secondly fill the images of this series with ID (SID) in the picture list : #region Fill Picture List //Bring all images in the series DBC.CommandText = "SELECT ImageID,FileName FROM Image where FLOOR(ImageID/100)= " + SID.ToString() + " ;"; ds = DBC.ExecuteQuery(); //Bring the folder where images of series are copied DBC.CommandText = "SELECT FolderPath FROM Series WHERE SID = " + SID.ToString() + " ;"; DataSet sds = DBC.ExecuteQuery(); //Images folder is . . . string imgFld = sds.Tables[0].Rows[0].ItemArray[0].ToString(); //Now put all images in the series in the picture list (picLstSerImage) for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string fname = ds.Tables[0].Rows[i].ItemArray[1].ToString(); string ImageID = ds.Tables[0].Rows[i].ItemArray[0].ToString(); imgFld = (imgFld.EndsWith("\\")) ? imgFld : imgFld + "\\"; imgFld = (imgFld.StartsWith("\\")) ? imgFld : "\\" + imgFld; string imgpath = this.SC.SettingsList[0].TrimEnd('\\') + imgFld + fname; Bitmap bmp = new Bitmap(imgpath); PictureListItem pItem = new PictureListItem(fname, bmp, true, null); ImageRecord = new imageRecord(ImageID, null, fname, null); pItem.Value = ImageRecord; pItem.Tag = imgpath; picLstSerImage.Items.Add(pItem); } #endregion //And finally fill the notes about the series #region Fill Series Notes DBC.CommandText = "SELECT Notes FROM Series_Notes where SID= " + SID.ToString() + " ;"; ds = DBC.ExecuteQuery(); if (ds.Tables[0].Rows.Count > 0) { rbnTxtNotes.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString(); } #endregion } else { throw new Exception("The database is not connected"); } #region Operations related to specific kind of data manipulation if (opr.ToLower() == "modify") //Modification { rbnBtnNotes.Visible = true; rbnBtnAddImage.Visible = true; rbnBtnRemoveImage.Visible = true; rbnBtnDelAll.Visible = true; rbnBtnManipulate.Visible = true; allowPatiantChange = true; } else //Deletion { int[] to_delete = new int[mListCats.Items.Count]; int j = 0; for (int i = 0; i < mListCats.Items.Count; i++) { if (mListCats.Items[i].CheckState == CheckState.Unchecked) { to_delete[j] = i; j++; } } for (int i = j; i >= 0; i--) { mListCats.Items.RemoveAt(i); } mListCats.ShowCheck = false; } #endregion } catch (Exception ex) { MessageBox.Show( ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void rbnBtnDone_Click(object sender, EventArgs e) { try { #region Insert Series if (opr.ToUpper() == "INSERT") { //Check if the series information are filled well . . . if ((rbnCboPatiant.SelectedItem != "Select Patiant") && (picLstSerImage.Items.Count > 0) && (rbnCboPatiant.SelectedItem != null)) { //Preparing the progress bar . . . int xx = picLstSerImage.Items.Count; xx = 100 / xx; proBarOpr.Visible = true; proBarOpr.BringToFront(); proBarOpr.Value = 0; //Create the physical path where the image and the series is contained int sid = int.Parse(rbnTxtSeriesID.Text); string serFolder = SC.SettingsList[0].TrimEnd('\\') + "\\" + sid.ToString(); Directory.CreateDirectory(serFolder); sid = sid * 100; int imgID = 0; //Extract image features for each image in the series : foreach (PictureListItem P in picLstSerImage.Items) { Application.DoEvents(); fe = new featureExtractor(P.Tag.ToString()); fv = fe.AllFeatures(); //Get all image information : string[] info = fe.GetImageInfo().Split('\n'); for (int i = 0; i < info.Length; i++) { info[i] = info[i].Trim(); } //Get image size and Dimensions string size = "", h = "", w = ""; for (int i = 0; i < info.Length; i++) { if (info[i].StartsWith("FileSize")) { size = info[i]; } else if (info[i].StartsWith("Width")) { w = info[i]; } else if (info[i].StartsWith("Height")) { h = info[i]; } } info = new string[2]; info[0] = size.Split(':')[1].Trim(); //Image size . . . info[1] = h.Split(':')[1].Trim() + "X" + w.Split(':')[1].Trim(); //Image Dimensions . . . imgID++; //Image ID in the series . . . int ID = sid + imgID; //Image ID in the database . . . //Create image record . . . ImageRecord = new imageRecord(ID.ToString(), info, P.Text, fv); // . . . and insert that record in the opened database if (!ImageRecord.InsertImage(DBC)) //If insertion is not done { throw new Exception("Failed to insert the image record with ID: " + ID.ToString() + "!"); //Throw an exception } //Copy image file from its location to where each image in the database is stored File.Copy(P.Tag.ToString(), serFolder + "\\" + P.Text, true); Application.DoEvents(); proBarOpr.Value += xx; } sid = sid / 100; //Determine series categories . . . List <category> catList = new List <category>(); for (int i = 0; i < mListCats.Items.Count; i++) { if (mListCats.Items[i].CheckState == CheckState.Checked) { catList.Add(new category(mListCats.Items[i].Description, null, null)); } } //Create series record . . . SeriesRecord = new Series(sid.ToString() , rbnCboPatiant.SelectedItem.Split('\t')[0] , sid.ToString() , this.rbnTxtNotes.Text, catList); //Try to insert the series . . . if (!SeriesRecord.InsertSeries(DBC)) //In insertion is not done { throw new Exception("Failed to insert this series !"); //Throw an exception } proBarOpr.Value = 100; proBarOpr.SendToBack(); proBarOpr.Visible = false; this.DialogResult = DialogResult.OK; this.Close();//Close when done } else { throw new Exception("Please fill all the fields !"); } } #endregion #region Modify Series else if (opr.ToUpper() == "MODIFY") { //Check if the fields are filled well . . . if ((rbnCboPatiant.SelectedItem != "Select Patiant") && (rbnCboSeriesID.SelectedItem != "Select Series")) { if (!(pat_changed || cats_changed || images_changed || notes_changed)) { this.DialogResult = DialogResult.None; MessageBox.Show("No change done to this series !", "Closing", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } //Preparing the progress bar . . . int xx = picLstSerImage.Items.Count; xx = 100 / xx; proBarOpr.Visible = true; proBarOpr.BringToFront(); proBarOpr.Value = 0; //Get the physical path where the image and the series is contained int sid = int.Parse(rbnCboSeriesID.SelectedItem); string serFolder = SC.SettingsList[0].TrimEnd('\\') + "\\" + sid.ToString(); sid = sid * 100; int imgID = 0; //Extract image features for each changed or new image in the series : foreach (PictureListItem P in picLstSerImage.Items) { Application.DoEvents(); string txt = P.Text.ToLower(); #region If image is removed if (txt.Contains("removed")) { if (txt.Contains("new")) { picLstSerImage.Items.Remove(P); } else { ImageRecord = (imageRecord)P.Value; if (ImageRecord.DeleteImage(DBC)) { P.Text = P.Text.ToLower(); P.Text = P.Text.Replace(" removed", ""); //File.Delete(serFolder + "\\" + P.Text); } else { throw new Exception("The image with ImageID : " + ImageRecord.ID + "\nCannot be deleted"); } } } #endregion #region If image is new and not removed else { if (!txt.Contains("removed") && (txt.Contains("new"))) { fe = new featureExtractor(P.Tag.ToString()); fv = fe.AllFeatures(); //Get all image information : string[] info = fe.GetImageInfo().Split('\n'); for (int i = 0; i < info.Length; i++) { info[i] = info[i].Trim(); } //Get image size and Dimensions string size = "", h = "", w = ""; for (int i = 0; i < info.Length; i++) { if (info[i].StartsWith("FileSize")) { size = info[i]; } else if (info[i].StartsWith("Width")) { w = info[i]; } else if (info[i].StartsWith("Height")) { h = info[i]; } } info = new string[2]; info[0] = size.Split(':')[1].Trim(); //Image size . . . info[1] = h.Split(':')[1].Trim() + "X" + w.Split(':')[1].Trim(); //Image Dimensions . . . imgID = getUnusedImageID(sid / 100); //Image ID in the series . . . int ID = imgID + 1; //Image ID in the database . . . //Create image record . . . P.Text = P.Text.ToLower(); P.Text = P.Text.Replace(" new", ""); ImageRecord = new imageRecord(ID.ToString(), info, P.Text, fv); // . . . and insert that record in the opened database if (!ImageRecord.InsertImage(DBC)) //If insertion is not done { throw new Exception("Failed to insert the new image record with ID: " + ID.ToString() + "!"); //Throw an exception } //Copy image file from its location to where each image in the database is stored File.Copy(P.Tag.ToString(), serFolder + "\\" + P.Text, true); } } #endregion #region If image is not new nor removed but changed if (txt.Contains("changed")) //Manipulated (Edited) image { //Do not do any thing to this image why?!!! . . . //simply because it was added by the manipulation process } #endregion Application.DoEvents(); proBarOpr.Value += xx; } sid = sid / 100; //Determine series categories . . . List <category> catList = new List <category>(); for (int i = 0; i < mListCats.Items.Count; i++) { if (mListCats.Items[i].CheckState == CheckState.Checked) { catList.Add(new category(mListCats.Items[i].Description, null, null)); } } //Create series record . . . SeriesRecord = new Series(sid.ToString() , rbnCboPatiant.SelectedItem.Split('\t')[0] , sid.ToString() , this.rbnTxtNotes.Text, catList); //Try to update the series . . . if (!SeriesRecord.UpdateSeries(DBC)) //If modification not done . . . { throw new Exception("Failed to update this series !"); //Throw an exception } proBarOpr.Value = 100; proBarOpr.SendToBack(); proBarOpr.Visible = false; this.DialogResult = DialogResult.OK; this.Close();//Close when done } else { throw new Exception("Please fill all the fields !"); } } #endregion #region Delete Series else if (opr.ToUpper() == "DELETE") { DialogResult dr = MessageBox.Show("Are you sure you want to delete this series and all its images ?", "Deletion", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { //Check if the fields are filled well . . . if ((rbnCboPatiant.SelectedItem != "Select Patiant") && (rbnCboSeriesID.SelectedItem != "Select Series")) { //Preparing the progress bar . . . int xx = picLstSerImage.Items.Count; xx = 100 / xx; proBarOpr.Visible = true; proBarOpr.BringToFront(); proBarOpr.Value = 0; //Get the physical path where the image and the series is contained int sid = int.Parse(rbnCboSeriesID.SelectedItem); string serFolder = SC.SettingsList[0].TrimEnd('\\') + "\\" + sid.ToString(); sid = sid * 100; int imgID = 0; //Delete each image in the series : foreach (PictureListItem P in picLstSerImage.Items) { Application.DoEvents(); string txt = P.Text.ToLower(); ImageRecord = (imageRecord)P.Value; if (!P.Text.ToLower().Contains("new")) { if (!ImageRecord.DeleteImage(DBC)) { throw new Exception("The image with ImageID : " + ImageRecord.ID + "\nCannot be deleted"); } } Application.DoEvents(); proBarOpr.Value += xx; } sid = sid / 100; //Determine series categories . . . List <category> catList = new List <category>(); for (int i = 0; i < mListCats.Items.Count; i++) { catList.Add(new category(mListCats.Items[i].Description, null, null)); } //Create series record . . . SeriesRecord = new Series(sid.ToString() , rbnCboPatiant.SelectedItem.Split('\t')[0] , sid.ToString() , this.rbnTxtNotes.Text, catList); //Try to delete the series . . . if (!SeriesRecord.DeleteSeries(DBC)) //If deletion not done . . . { throw new Exception("Failed to delete this series !"); //Throw an exception } proBarOpr.Value = 100; proBarOpr.SendToBack(); proBarOpr.Visible = false; this.DialogResult = DialogResult.OK; this.Close();//Close when done } } } #endregion } catch (Exception ex) { MessageBox.Show( ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (proBarOpr.Visible) { proBarOpr.Visible = false; } } }