public void addToActiveImages(ImageObject img) { ThreadPool.QueueUserWorkItem(delegate { using (MySqlConnection c = new MySqlConnection(DBPATH)) { c.Open(); string query = "INSERT into activeimages(image, x, y, istext) VALUES('" + img.getBase64String() + "'," + prevX + ", " + prevY + ", -1)"; prevY += 50; MySqlCommand mCmd = new MySqlCommand(query, c); mCmd.ExecuteNonQuery(); } }); }
public void addImage(ImageObject img) { dbManager.addToActiveImages(img); }
public List<ImageObject> getActiveImages() { List<ImageObject> retVal = new List<ImageObject>(); using (MySqlConnection c = new MySqlConnection(DBPATH)) { c.Open(); MySqlCommand mCmd = new MySqlCommand(string.Format("SELECT * FROM activeimages ORDER BY id ASC;"), c); using (MySqlDataReader r = mCmd.ExecuteReader()) { while (r.Read()) { switch (r.GetInt32("istext")) { case -1: String s = r.GetString("image"); Byte[] bitmapData = new Byte[s.Length]; bitmapData = Convert.FromBase64String(FixBase64ForImage(s)); System.IO.MemoryStream streamBitmap = new System.IO.MemoryStream(bitmapData); streamBitmap.Seek(0, SeekOrigin.Begin); Bitmap bitImage = new Bitmap((Bitmap)Image.FromStream(streamBitmap)); using (var stream = new MemoryStream(bitmapData)) { var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = stream; bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.EndInit(); bitmap.Freeze(); ImageObject imgObj = new ImageObject(bitmap, s, r.GetInt32("x"), r.GetInt32("y"), r.GetInt32("id")); retVal.Add(imgObj); } streamBitmap.Close(); break; case 1: ImageObject textObj = new ImageObject(r.GetString("text"), r.GetInt32("x"), r.GetInt32("y"), r.GetInt32("id")); retVal.Add(textObj); break; default: break; } } } } return retVal; }
public List<ImageObject> getGalleryUpdatedImages(int latestId) { List<ImageObject> retVal = new List<ImageObject>(); using (MySqlConnection c = new MySqlConnection(DBPATH)) { c.Open(); MySqlCommand mCmd = new MySqlCommand(string.Format("SELECT * FROM galleryimages WHERE id > " + latestId + " ORDER BY id ASC;"), c); using (MySqlDataReader r = mCmd.ExecuteReader()) { while (r.Read()) { String s = r.GetString("image"); Byte[] bitmapData = new Byte[s.Length]; bitmapData = Convert.FromBase64String(FixBase64ForImage(s)); System.IO.MemoryStream streamBitmap = new System.IO.MemoryStream(bitmapData); streamBitmap.Seek(0, SeekOrigin.Begin); Bitmap bitImage = new Bitmap((Bitmap)Image.FromStream(streamBitmap)); using (var stream = new MemoryStream(bitmapData)) { var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = stream; bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.EndInit(); bitmap.Freeze(); ImageObject obj = new ImageObject(bitmap, s, r.GetInt32("x"), r.GetInt32("y"), r.GetInt32("id")); retVal.Add(obj); } streamBitmap.Close(); } } } return retVal; }