/// <summary> /// Creates a new instance of <see cref="KanvasImage"/>. /// </summary> /// <param name="imageState">The image plugin the plugin information come from.</param> /// <param name="imageInfo">The image info to represent.</param> public KanvasImage(IImageState imageState, ImageInfo imageInfo) { ContractAssertions.IsNotNull(imageState, nameof(imageState)); ContractAssertions.IsNotNull(imageInfo, nameof(imageInfo)); ContractAssertions.IsElementContained(imageState.Images, imageInfo, nameof(imageState.Images), nameof(imageInfo)); _imageState = imageState; _imageInfo = imageInfo; }
public ImageContext(IStateInfo stateInfo, IContext parentContext) { ContractAssertions.IsNotNull(stateInfo, nameof(stateInfo)); ContractAssertions.IsNotNull(parentContext, nameof(parentContext)); _stateInfo = stateInfo; _imageState = _stateInfo.PluginState as IImageState; _parentContext = parentContext; }
public ImageContext(IFileState stateInfo, IContext parentContext, IProgressContext progressContext) : base(progressContext) { ContractAssertions.IsNotNull(stateInfo, nameof(stateInfo)); ContractAssertions.IsNotNull(parentContext, nameof(parentContext)); _stateInfo = stateInfo; _imageState = _stateInfo.PluginState as IImageState; _parentContext = parentContext; }
public EncodeImageViewModel(PluginManager pluginManager, IImageState state, ImageInfo imageInfo) { _pluginManager = pluginManager; _state = state; _kanvasImage = new KanvasImage(state, imageInfo); SelectedEncoding = state.SupportedEncodings[_kanvasImage.ImageFormat]; SourceImage = _kanvasImage.GetImage().ToBitmapImage(); OutputImage = SourceImage; }
public ImageInfo Load(Stream input, IFileManager pluginManager) { using var br = new BinaryReaderX(input); // Read header _header = br.ReadType <ImgxHeader>(); // Load KTX _imageState = LoadKtx(input, "file.ktx", pluginManager).Result; return(_imageState.Images[0].ImageInfo); }
private void CheckIntegrity(IImageState imageState) { var encodingDefinition = imageState.EncodingDefinition; // Check if any encodings are given if (!encodingDefinition.HasColorEncodings && !encodingDefinition.HasIndexEncodings) { throw new InvalidOperationException("The plugin has no supported encodings defined."); } if (encodingDefinition.HasIndexEncodings && !encodingDefinition.HasPaletteEncodings) { throw new InvalidOperationException("The plugin has no supported palette encodings defined."); } }
// Constructor public ImageEditorViewModel(PluginManager pluginManager, IStateInfo koreFile) { _pluginManager = pluginManager; KoreFile = koreFile; _state = KoreFile.PluginState as IImageState; if (_state?.Images != null) { KanvasImages = new ObservableCollection <KanvasImage>(_state.Images.Select(x => new KanvasImage(_state, x))); } SelectedKanvasImage = KanvasImages?.FirstOrDefault(); SelectedZoomLevel = 1; }
private void InjectImages(IImageState imageState, UPath filePath, IFileSystem destinationFileSystem) { for (var i = 0; i < imageState.Images.Count; i++) { var img = imageState.Images[i]; var path = filePath / (img.Name ?? $"{i:00}") + ".png"; if (!destinationFileSystem.FileExists(path)) { continue; } var openedImage = (Bitmap)Image.FromStream(destinationFileSystem.OpenFile(path)); img.SetImage(openedImage); } }
private void ExtractImage(IImageState imageState, IFileSystem destinationFileSystem, UPath filePath) { if (imageState.Images.Count > 0) { CreateDirectory(destinationFileSystem, filePath); } var index = 0; foreach (var img in imageState.Images) { var fileStream = destinationFileSystem.OpenFile(filePath / (img.Name ?? $"{index:00}") + ".png", FileMode.Create, FileAccess.Write); img.GetImage().Save(fileStream, ImageFormat.Png); fileStream.Close(); index++; } }