using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Media; namespace ROIEditor { public class ImagenEstado { public double ZoomScaleX { get; set; } public double ZoomScaleY { get; set; } public double HorizontalOffset { get; set; } public double VerticalOffset { get; set; } public string NombreImagen; // Constructor sin parámetros public ImagenEstado() { } public ImagenEstado(string imageNameActual) { NombreImagen = imageNameActual; } public string PathPlantillasJson() { string jsonPath = Path.ChangeExtension(NombreImagen, ".json"); var imagePath = Path.Combine(Directory.GetCurrentDirectory(), "Plantillas", jsonPath); return imagePath; } public string PathPlantillasPNG() { string jsonPath = Path.ChangeExtension(NombreImagen, ".png"); var imagePath = Path.Combine(Directory.GetCurrentDirectory(), "Plantillas", jsonPath); return imagePath; } public void SalvarEstadoJSON() { // Cambia la extensión del archivo de imagen a .json string jsonPath = PathPlantillasJson(); // Serializa el estado de la imagen a JSON string json = JsonConvert.SerializeObject(NombreImagen, Formatting.Indented); // Escribe el JSON en un archivo File.WriteAllText(jsonPath, json); } public void CargarEstadoJSON() { string jsonPath = PathPlantillasJson(); if (File.Exists(jsonPath)) { string json = File.ReadAllText(jsonPath); ImagenEstado estadoCargado = JsonConvert.DeserializeObject(json); // Usar reflexión para copiar todas las propiedades foreach (PropertyInfo prop in typeof(ImagenEstado).GetProperties()) { if (prop.CanRead && prop.CanWrite) { prop.SetValue(this, prop.GetValue(estadoCargado, null), null); } } } } } }