0 Members and 1 Guest are viewing this topic.
Hey Jim,Avais-tu codé quelque peu ce projet? Je cherche un moyen d'avoir le niveau des tuiles au niveau maximum.
Concernant le tile level, peut-être peux-tu regarder par rapport à la définition de l'image ? Une image en 2048*2048 qui couvre soit 5 soit 10 km^2 (au pif hein) pourrait changer de level. Mais là je ne peux pas vraiment t'aider.
void Split(Bitmap Input, int tilelength) { int cols = (int)Math.Truncate((float)Input.Width / (float)tilelength); int rows = (int)Math.Truncate((float)Input.Height / (float)tilelength); int rowpad = (rows - 1).ToString().Length; int colpad = (cols - 1).ToString().Length; string filepath = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, UniqueID.GetNewID()); Directory.CreateDirectory(filepath); for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { string name = String.Format("r{1}c{0}.bmp", c.ToString().PadLeft(colpad, '0'), r.ToString().PadLeft(rowpad, '0')); string fName = System.IO.Path.Combine(filepath, name); Rectangle rz = new Rectangle(c * tilelength, r * tilelength, tilelength, tilelength); Bitmap bmpCrop = Input.Clone(rz, System.Drawing.Imaging.PixelFormat.DontCare); bmpCrop.Save(fName); Application.DoEvents(); } } Status.Text = "Finish !"; }
void CropAndSave(object state) { try { object[] State = state as object[]; Bitmap Input = (Bitmap)State[0]; Rectangle r = (Rectangle)State[1]; string filename = (string)State[2]; Bitmap bmpCrop = Input.Clone(r, System.Drawing.Imaging.PixelFormat.DontCare); bmpCrop.Save(filename); } finally { lock (_ActiveWorkersLock) { --_CountOfActiveWorkers; Monitor.PulseAll(_ActiveWorkersLock); } } } void Split(Bitmap Input, int tilelength) { try { if (!Miscallenous.IsPowerOfTwo((ulong)tilelength)) throw new ArgumentException("Tile Length must be power of two"); Status.Text = "Thread Pool started. Booting up operations ..."; sw.Restart(); int cols = (int)Math.Truncate((float)Input.Width / (float)tilelength); int rows = (int)Math.Truncate((float)Input.Height / (float)tilelength); int rowpad = (rows - 1).ToString().Length; int colpad = (cols - 1).ToString().Length; string filepath = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, UniqueID.GetNewID()); Directory.CreateDirectory(filepath); for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { string name = String.Format("r{1}c{0}.bmp", c.ToString().PadLeft(colpad, '0'), r.ToString().PadLeft(rowpad, '0')); string fName = System.IO.Path.Combine(filepath, name); Rectangle rect = new Rectangle(c * tilelength, r * tilelength, tilelength, tilelength); lock (_ActiveWorkersLock) ++_CountOfActiveWorkers; System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(CropAndSave), new object[] { Input.Clone(), rect, fName }); Status.Text = String.Format("{3:00} thread{4} running. | Elapsed {0:00}:{1:00}:{2:000}", Math.Truncate(sw.Elapsed.TotalMinutes), sw.Elapsed.Seconds, sw.Elapsed.Milliseconds, _CountOfActiveWorkers, _CountOfActiveWorkers == 1 ? "" : "s"); Application.DoEvents(); } } lock (_ActiveWorkersLock) { while (_CountOfActiveWorkers > 0) { Status.Text = String.Format("{3:00} thread{4} running. | Elapsed {0:00}:{1:00}:{2:000}", Math.Truncate(sw.Elapsed.TotalMinutes), sw.Elapsed.Seconds, sw.Elapsed.Milliseconds, _CountOfActiveWorkers, _CountOfActiveWorkers == 1 ? "" : "s"); Application.DoEvents(); Monitor.Wait(_ActiveWorkersLock); } } sw.Stop(); Status.Text = "Image tiling finished. Takes " + Miscallenous.GetDirectorySize(filepath) / (1024 * 1024) + " Mb. | " + String.Format("Elapsed {0:00}:{1:00}:{2:000}", Math.Truncate(sw.Elapsed.TotalMinutes), sw.Elapsed.Seconds, sw.Elapsed.Milliseconds); Process.Start(filepath); } catch (Exception e) { MessageBox.Show("Erreur :\n" + e.Message, "ERREUR !", MessageBoxButtons.OK, MessageBoxIcon.Error); } }